I have a personal project to cache some rss feeds locally on my NAS drive (using it’s built-in web server and a chron job) so that I won’t miss “posts” when my desktop machine is switched off.
So far I have a simple php script set up that stores the cache for a single feed in a MySQL database. I will expand this to include multiple feeds and loop through them all, but for now I just want to make sure that what I want to do is possible. As SimplePie clears the cache when it expires, I was thinking of creating a copy of the “cache_data” and “items” tables to use like an archive – if I copy all new records into the new tables then it wouldn’t matter if SimplePie clear’s it’s own cache tables because I already have a copy of the items.
What I need to do now is create the output rss/xml file and I’m wondering if SimplePie can be used for this. I see two possibilities;
- Get SimplePie to use the “archive” tables as it’s cache location with expiring disabled so that nothing is removed.
- Read the data from the “arcive” tables myself and use SimplePie to process the data and build the rss feed.
I’ve had a look around the SimplePie documentation and through SimplePie.inc to see if I could find anything to point me in the right direction, but this is my first real php project and SimplePie contains rather a lot of complicated looking code. Any suggestions or pointers would be very appreciated 🙂
Create your own SimplePie_Cache class, filling in the methods with code that gets and sets from your caching tables, or memcached, filesystem, or wherever. The only thing you need to know is to use $this->name as the name of the cache key for each of the functions.
Then, register the cache class to your feed: