Source for file rss_cache.inc
Documentation is available at rss_cache.inc
* Project: MagpieRSS: a simple RSS integration tool
* File: rss_cache.inc, a simple, rolling(no GC), cache
* for RSS objects, keyed on URL.
* Author: Kellan Elliott-McCrea <kellan@protest.net>
* The lastest version of MagpieRSS can be obtained from:
* http://magpierss.sourceforge.net
* For questions, help, comments, discussion, etc., please join the
* http://lists.sourceforge.net/lists/listinfo/magpierss-general
var $BASE_CACHE =
'./cache'; // where the cache files are stored
var $MAX_AGE =
3600; // when are files stale, default one hour
var $ERROR =
""; // accumulate error messages
// attempt to make the cache directory
"Cache couldn't make dir '" .
$this->BASE_CACHE .
"'."
/*=======================================================================*\
Purpose: add an item to the cache, keyed on url
Input: url from wich the rss file was fetched
\*=======================================================================*/
function set ($url, $rss) {
$fp =
@fopen( $cache_file, 'w' );
"Cache unable to open file for writing: $cache_file"
/*=======================================================================*\
Purpose: fetch an item from the cache
Input: url from wich the rss file was fetched
Output: cached object on HIT, false on MISS
\*=======================================================================*/
"Cache doesn't contain: $url (cache file: $cache_file)"
$fp =
@fopen($cache_file, 'r');
"Failed to open cache file for reading: $cache_file"
if ($filesize =
filesize($cache_file) ) {
/*=======================================================================*\
Purpose: check a url for membership in the cache
and whether the object is older then MAX_AGE (ie. STALE)
Input: url from wich the rss file was fetched
Output: cached object on HIT, false on MISS
\*=======================================================================*/
// find how long ago the file was added to the cache
// and whether that is longer then MAX_AGE
// object exists and is current
// object exists but is old
/*=======================================================================*\
\*=======================================================================*/
/*=======================================================================*\
\*=======================================================================*/
/*=======================================================================*\
Purpose: map url to location in cache
Input: url from wich the rss file was fetched
\*=======================================================================*/
return join( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) );
/*=======================================================================*\
\*=======================================================================*/
function error ($errormsg, $lvl=
E_USER_WARNING) {
// append PHP's error message if track_errors enabled
if ( isset
($php_errormsg) ) {
$errormsg .=
" ($php_errormsg)";
$this->ERROR =
$errormsg;
function debug ($debugmsg, $lvl=
E_USER_NOTICE) {
$this->error("MagpieRSS [debug] $debugmsg", $lvl);
Documentation generated on Tue, 01 May 2007 16:47:06 +0200 by phpDocumentor 1.3.2