Source for file Cache.php

Documentation is available at Cache.php

  1. <?
  2.  
  3. /** A cache.
  4.  *
  5.  * @package    php-lastfm-api
  6.  * @author  Felix Bruns <felixbruns@web.de>
  7.  * @version    1.0
  8.  */
  9. abstract class Cache {
  10.     /** The CachePolicy that's used.
  11.      *
  12.      * @var        CachePolicy 
  13.      * @access    private
  14.      */
  15.     private $policy;
  16.  
  17.     /** Protected constructor that sets a DefaultCachePolicy.
  18.      *
  19.      * @access    protected
  20.      */
  21.     protected function __construct(){
  22.         $this->policy new DefaultCachePolicy();
  23.     }
  24.  
  25.     /** Returns the CachePolicy that's used.
  26.      *
  27.      * @return    CachePolicy    A CachePolicy object.
  28.      * @access    public
  29.      * @see        CachePolicy
  30.      */
  31.     public function getPolicy(){
  32.         return $this->policy;
  33.     }
  34.  
  35.     /** Sets the CachePolicy to be used.
  36.      *
  37.      * @param    CachePolicy    $policy    A CachePolicy object.
  38.      * @access    public
  39.      * @see        CachePolicy
  40.      */
  41.     public function setPolicy(CachePolicy $policy){
  42.         $this->policy $policy;
  43.     }
  44.  
  45.     /** Checks if data associated with a hash exists in the cache.
  46.      *
  47.      * @param    string    $hash    The hash of the entry to be checked.
  48.      * @return    boolean            true if the entry exists, otherwise false.
  49.      * @access    public
  50.      */
  51.     public abstract function contains($hash);
  52.  
  53.     /** Loads data from the cache.
  54.      *
  55.      * @param    string    $hash    The hash of the entry to be loaded.
  56.      * @return    string            The cached data.
  57.      * @access    public
  58.      */
  59.     public abstract function load($hash);
  60.  
  61.     /** Removes data from the cache.
  62.      *
  63.      * @param    string    $hash    The hash of the entry to be removed.
  64.      * @access    public
  65.      */
  66.     public abstract function remove($hash);
  67.  
  68.     /** Stores data in the cache.
  69.      *
  70.      * @param    string    $hash        The hash of the data to be stored.
  71.      * @param    string    $data        The data to be stored.
  72.      * @param    string    $expiration    The expiration time of the data (unix timestamp).
  73.      * @access    public
  74.      */
  75.     public abstract function store($hash$data$expiration);
  76.  
  77.     /** Checks if data associated with a hash is expired.
  78.      *
  79.      * @param    string    $hash    The hash of the entry to be checked.
  80.      * @return    boolean            true if the entry is expired, otherwise false.
  81.      * @access    public
  82.      */
  83.     public abstract function isExpired($hash);
  84.  
  85.     /** Removes all data from the cache.
  86.      *
  87.      * @access    public
  88.      */
  89.     public abstract function clear();
  90.  
  91.     /** Creates a hash from last.fm API request parameters.
  92.      *
  93.      * @param    array    $params    An associative array of last.fm API request parameters.
  94.      * @return    string            A calculated hexadecimal SHA1 hash.
  95.      *
  96.      * @static
  97.      * @access    public
  98.      */
  99.     public static function createHash($params){
  100.         $string '';
  101.  
  102.         sort($params);
  103.  
  104.         foreach($params as $param => $value){
  105.             $string .= $param.$value;
  106.         }
  107.  
  108.         return sha1($string);
  109.     }
  110. }
  111.  
  112. ?>

Documentation generated on Mon, 22 Dec 2008 16:57:31 +0100 by phpDocumentor 1.4.1