Source for file DefaultCachePolicy.php

Documentation is available at DefaultCachePolicy.php

  1. <?
  2.  
  3. /** A cache policy.
  4.  *
  5.  * @package    php-lastfm-api
  6.  * @author  Felix Bruns <felixbruns@web.de>
  7.  * @version    1.0
  8.  */
  9. final class DefaultCachePolicy implements CachePolicy {
  10.     private static $MINUTE;
  11.     private static $HOUR;
  12.     private static $DAY;
  13.     private static $WEEK;
  14.     private static $MONTH;
  15.     private static $YEAR;
  16.  
  17.     /** last.fm API methods to be cached for a week.
  18.      *
  19.      * @var        array 
  20.      * @access    private
  21.      */
  22.     private $weeklyMethods;
  23.  
  24.     /** The expiration time of weekly charts (defaults to a week).
  25.      *
  26.      * @var        integer 
  27.      * @access    private
  28.      */
  29.     private $weeklyChartsExpiration;
  30.  
  31.     /** Creates a DaultCachePolicy.
  32.      *
  33.      * @access    public
  34.      */
  35.     public function __construct(){
  36.         $this->MINUTE  =                 60;
  37.         $this->HOUR    $this->MINUTE 60;
  38.         $this->DAY     $this->HOUR   24;
  39.         $this->WEEK    $this->DAY    *  7;
  40.         $this->MONTH   $this->WEEK   *  4.34812141;
  41.         $this->YEAR    $this->MONTH  12;
  42.  
  43.         $this->weeklyMethods array(
  44.             'artist.getSimilar',
  45.             'tag.getSimilar',
  46.             'track.getSimilar',
  47.             'artist.getTopAlbums',
  48.             'artist.getTopTracks',
  49.             'geo.getTopArtists',
  50.             'geo.getTopTracks',
  51.             'tag.getTopAlbums',
  52.             'tag.getTopArtists',
  53.             'tag.getTopTags',
  54.             'tag.getTopTracks',
  55.             'user.getTopAlbums',
  56.             'user.getTopArtists',
  57.             'user.getTopTags',
  58.             'user.getTopTracks'
  59.         );
  60.  
  61.         $this->weeklyChartsExpiration $this->WEEK;
  62.     }
  63.  
  64.     /** Returns the expiration time by interpreting last.fm API request parameters.
  65.      *
  66.      * @param    array    $params    An associative array of last.fm API request parameters.
  67.      * @return    integer            Expiration time in seconds.
  68.      *
  69.      * @access    public
  70.      */
  71.     public function getExpirationTime($params){
  72.         $method $params['method'];
  73.  
  74.         if(stripos($method'Weekly'!== false && stripos($method'List'=== false){
  75.             if(in_array('to'$params&& in_array('from'$params)){
  76.                 return $this->YEAR;
  77.             }
  78.             else{
  79.                 return $this->weeklyChartsExpiration;
  80.             }
  81.         }
  82.  
  83.         return in_array($method$this->weeklyMethods$this->WEEK : -1;
  84.     }
  85.  
  86.     /** Returns the expiration time of weekly charts.
  87.      *
  88.      * @return    integer    The expiration time in seconds.
  89.      *
  90.      * @access    public
  91.      */
  92.     public function getWeeklyChartsExpiration(){
  93.         return $this->weeklyChartsExpiration;
  94.     }
  95.  
  96.     /** Sets the expiration time of weekly charts.
  97.      *
  98.      * @param    integer    $expiration    Expiration time in seconds.
  99.      * @access    public
  100.      */
  101.     public function setWeeklyChartsExpiration($expiration){
  102.         $this->weeklyChartsExpiration $expiration;
  103.     }
  104. }
  105.  
  106. ?>

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