Source for file MemoryCache.php

Documentation is available at MemoryCache.php

  1. <?
  2.  
  3. /** A memory cache.
  4.  *
  5.  * @package    php-lastfm-api
  6.  * @author  Felix Bruns <felixbruns@web.de>
  7.  * @version    1.0
  8.  */
  9. final class MemoryCache extends Cache {
  10.     /** The array where the cache data is stored.
  11.      *
  12.      * @var        array 
  13.      * @access    private
  14.      */
  15.     private $cache;
  16.  
  17.     /** Constructor that sets up the MemoryCache.
  18.      *
  19.      * @access    public
  20.      */
  21.     public function __construct(){
  22.         parent::__construct();
  23.  
  24.         $this->cache array();
  25.     }
  26.  
  27.     /** Checks if data associated with a hash exists in the cache.
  28.      *
  29.      * @param    string    $hash    The hash of the entry to be checked.
  30.      * @return    boolean            true if the entry exists, otherwise false.
  31.      * @access    public
  32.      */
  33.     public function contains($hash){
  34.         return array_key_exists($hash$this->cache);
  35.     }
  36.  
  37.     /** Loads data from the cache.
  38.      *
  39.      * @param    string    $hash    The hash of the entry to be loaded.
  40.      * @return    string            The cached data.
  41.      * @access    public
  42.      */
  43.     public function load($hash){
  44.         return $this->cache[$hash]['data'];
  45.     }
  46.  
  47.     /** Removes data from the cache.
  48.      *
  49.      * @param    string    $hash    The hash of the entry to be removed.
  50.      * @access    public
  51.      */
  52.     public function remove($hash){
  53.         unset($this->cache[$hash]);
  54.     }
  55.  
  56.     /** Stores data in the cache.
  57.      *
  58.      * @param    string    $hash        The hash of the data to be stored.
  59.      * @param    string    $data        The data to be stored.
  60.      * @param    string    $expiration    The expiration time of the data (unix timestamp).
  61.      * @access    public
  62.      */
  63.     public function store($hash$data$expiration){
  64.         $this->cache[$hasharray(
  65.             'data'       => $data,
  66.             'expiration' => $expiration
  67.         );
  68.     }
  69.  
  70.     /** Removes all data from the cache.
  71.      *
  72.      * @access    public
  73.      */
  74.     public function clear(){
  75.         $this->cache array();
  76.     }
  77.  
  78.     /** Checks if data associated with a hash is expired.
  79.      *
  80.      * @param    string    $hash    The hash of the entry to be checked.
  81.      * @return    boolean            true if the entry is expired, otherwise false.
  82.      * @access    public
  83.      */
  84.     public function isExpired($hash){
  85.         $expiration $this->cache[$hash]['expiration'];
  86.  
  87.         return (time(intval($expiration));
  88.     }
  89. }
  90.  
  91. ?>

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