SimplePie Caching Functionality (possibly its extension)

I have a personal project for caching some rss channels locally on my NAS (using the built-in web server and working with the cron) so that I don’t miss “messages” when my desktop computer is turned off.

So far I have a simple php script setup that stores the cache for a single channel in a MySQL database. I will expand this to include several channels and skip them, but for now I just want to make sure that what I want to do is possible. Since SimplePie clears the cache when it expires, I thought about creating a copy of the cache_data and items tables for use as an archive — if I copy all the new entries to new tables, then it would not matter if SimplePie clear its own cache tables because I already have a copy of the elements.

Now I need to create the rss / xml output file, and I am wondering if SimplePie can be used for this. I see two possibilities:

  • Get SimplePie to use the archive tables as the expiration cache location so that nothing is deleted.
  • Read the data from the "arc" tables yourself and use SimplePie to process the data and build the rss channel.

I looked through the documentation of SimplePie and through SimplePie.inc to find out if I can find anything to point me in the right direction, but this is my first real php project, and SimplePie contains quite a lot of complex looking code. Any suggestions or pointers would be greatly appreciated :)

+3
source share
1 answer

SimplePie_Cache, , , memcached, . , , $this- > name .

class MySimplePie_Cache extends SimplePie_Cache {
/**
 * Create a new cache object
 *
 * @param string $location Location string (from SimplePie::$cache_location)
 * @param string $name Unique ID for the cache
 * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
 */
  function __construct($location, $name, $extension) {
    $this->name = $name;
  }

  static function create($location, $filename, $extension) {
    return new MySimplePie_Cache($location, $filename, $extension);
  }

  function save($data) {
     // TODO: save $data to $this->name cache entry
     return true;
  }

  function load() {
     // TODO: load $data from $this->name cache entry
     return $data;
  }

  function mtime() {
    return time(); // this will disable any expiration checks
  }

  function touch() {
    return true; // not necessary, we don't need to update times, no expiration
  }

  function unlink() {
    return true;  // nothing will be removed from the cache
  }
}

:

$feed = new SimplePie();
$feed->set_cache_class("MySimplePie_Cache");
+1

All Articles