I’d like to build a simple php script to cache remote JSON files every hour.
Ideally, I would like to call the cached version like this:
jsoncache.php?uri=http://api.crunchbase.com/v/1/company/evernote.js
Does a script like this already exist? Can anyone help me with some example code?
Alternatively, is there a web service that does this?
Thanks!
Not sure if something like this already exists (although I’d be surprised if it didn’t). You could pull the data in PHP and save it to disk while storing the URL, a timestamp and the filename in a DB. When you get a request, you would do something like
SELECT filename, timestamp FROM CacheList WHERE URL= ?(where ? =$_POST['url']). If thetimestamp + 3600 < time()then just serve up the file you already have, otherwise re-download it, update the DB and serve up the new page.