topical media & game development 
  
  
    
    
  
 mashup-delicious-11-delcache-lib-rss-cache.inc / inc
  <?php
  /*
   * 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>
   * Version:     0.51
   * License:     GPL
   *
   * The lastest version of MagpieRSS can be obtained from:
   * http://magpierss.sourceforge.net
   *
   * For questions, help, comments, discussion, etc., please join the
   * Magpie mailing list:
   * http://lists.sourceforge.net/lists/listinfo/magpierss-general
   *
   */
  
  class RSSCache {
      var MAX_AGE    = 3600;         // when are files stale, default one hour
      var base='', base ) {
              base;
          }
          if ( this->MAX_AGE = this->BASE_CACHE ) ) {
              this->BASE_CACHE, 0755 );
              
              // if make failed 
              if ( ! this->error(
                      "Cache couldn't make dir '" . url, this->ERROR = "";
          this->file_name( fp = @fopen( fp ) {
              cache_file"
              );
              return 0;
          }
          
          
          this->serialize( fp, fp );
          
          return url) {
          cache_file = url );
          
          if ( ! file_exists( this->debug( 
                  "Cache doesn't contain: cache_file)"
              );
              return 0;
          }
          
          cache_file, 'r');
          if ( ! this->error(
                  "Failed to open cache file for reading: filesize = filesize(data = fread( cache_file) );
                  this->unserialize( rss;
              }
              
              return 0;
      }
  
  /*=======================================================================*\
      Function:   check_cache
      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 
  \*=======================================================================*/     
      function check_cache ( this->ERROR = "";
          this->file_name( filename ) ) {
              // find how long ago the file was added to the cache
              // and whether that is longer then MAX_AGE
              filename );
              mtime;
              if ( age ) {
                  // object exists and is current
                  return 'HIT';
              }
              else {
                  // object exists but is old
                  return 'STALE';
              }
          }
          else {
              // object does not exist
              return 'MISS';
          }
      }
  
          function cache_age( filename = url );
                  if ( file_exists( mtime = filemtime( age = time() - age;
                  }
                  else {
                          return -1;        
                  }
          }
          
  /*=======================================================================*\
      Function:   serialize
  \*=======================================================================*/     
      function serialize ( rss );
      }
  
  /*=======================================================================*\
      Function:   unserialize
  \*=======================================================================*/     
      function unserialize ( data );
      }
      
  /*=======================================================================*\
      Function:   file_name
      Purpose:    map url to location in cache
      Input:      url from wich the rss file was fetched
      Output:     a file name
  \*=======================================================================*/     
      function file_name (filename = md5( this->BASE_CACHE, errormsg, php_errormsg) ) { 
              php_errormsg)";
          }
          errormsg;
          if ( MAGPIE_DEBUG ) {
              trigger_error( lvl);
          }
          else {
              error_log( debugmsg, this->error("MagpieRSS [debug] lvl);
          }
      }
  
  }
  
  ?>
  
  
  
(C) Æliens 
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. 
In case of other copyright issues, contact the author.