コード例 #1
0
ファイル: TwoLevels.php プロジェクト: netvlies/zf
 /**
  * Test if a cache is available for the given id and (if yes) return it (false else)
  *
  * Note : return value is always "string" (unserialization is done by the core not by the backend)
  *
  * @param  string  $id                     Cache id
  * @param  boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
  * @return string|false cached datas
  */
 public function load($id, $doNotTestCacheValidity = false)
 {
     $res = $this->_fastBackend->load($id, $doNotTestCacheValidity);
     if ($res === false) {
         $res = $this->_slowBackend->load($id, $doNotTestCacheValidity);
         if ($res === false) {
             // there is no cache at all for this id
             return false;
         }
     }
     $array = unserialize($res);
     // maybe, we have to refresh the fast cache ?
     if ($this->_options['auto_refresh_fast_cache']) {
         if ($array['priority'] == 10) {
             // no need to refresh the fast cache with priority = 10
             return $array['data'];
         }
         $newFastLifetime = $this->_getFastLifetime($array['lifetime'], $array['priority'], time() - $array['expire']);
         // we have the time to refresh the fast cache
         $usage = $this->_getFastFillingPercentage('loading');
         if ($array['priority'] > 0 && 10 * $array['priority'] >= $usage) {
             // we can refresh the fast cache
             $preparedData = $this->_prepareData($array['data'], $array['lifetime'], $array['priority']);
             $this->_fastBackend->save($preparedData, $id, array(), $newFastLifetime);
         }
     }
     return $array['data'];
 }
コード例 #2
0
ファイル: TwoLevels.php プロジェクト: test3metizsoft/test
 /**
  * Test if a cache is available for the given id and (if yes) return it (false else)
  *
  * Note : return value is always "string" (unserialization is done by the core not by the backend)
  *
  * @param  string  $id                     Cache id
  * @param  boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
  * @return string|false cached datas
  */
 public function load($id, $doNotTestCacheValidity = false)
 {
     $resultFast = $this->_fastBackend->load($id, $doNotTestCacheValidity);
     if ($resultFast === false) {
         $resultSlow = $this->_slowBackend->load($id, $doNotTestCacheValidity);
         if ($resultSlow === false) {
             // there is no cache at all for this id
             return false;
         }
     }
     $array = $resultFast !== false ? unserialize($resultFast) : unserialize($resultSlow);
     //In case no cache entry was found in the FastCache and auto-filling is enabled, copy data to FastCache
     if ($resultFast === false && $this->_options['auto_fill_fast_cache']) {
         $preparedData = $this->_prepareData($array['data'], $array['lifetime'], $array['priority']);
         $this->_fastBackend->save($preparedData, $id, array(), $array['lifetime']);
     } elseif ($this->_options['auto_refresh_fast_cache']) {
         if ($array['priority'] == 10) {
             // no need to refresh the fast cache with priority = 10
             return $array['data'];
         }
         $newFastLifetime = $this->_getFastLifetime($array['lifetime'], $array['priority'], time() - $array['expire']);
         // we have the time to refresh the fast cache
         $usage = $this->_getFastFillingPercentage('loading');
         if ($array['priority'] > 0 && 10 * $array['priority'] >= $usage) {
             // we can refresh the fast cache
             $preparedData = $this->_prepareData($array['data'], $array['lifetime'], $array['priority']);
             $this->_fastBackend->save($preparedData, $id, array(), $newFastLifetime);
         }
     }
     return $array['data'];
 }