The latest version of ND.edu makes use of A LOT of external data sources. To make sure the site runs reliably, even in the case of an outage by one of the external feeds, I put together a fairly simple PHP class to handle the local caching of feeds.
It basically works like this:
- Create the class with the local file-name (whatever you want) and the external source (and an optional expires)
- The class will check if the local file exists and if it has expired
- If it has expired, it will try and fetch the remote source
- If the remote source is a-ok, it will pull a fresh copy and save it to a “cache” folder
- If remote source is unavailable or too slow, the class will fall-back to the expired (cached) file