Ejemplo n.º 1
0
 /**
  * Let's you retrieve the validity time of the cache entries.
  *
  * @param CacheKey $cacheKey The current cache key.
  *
  * @return int The validity time of the cache entry in seconds.
  *
  * @author Christian Achatz
  * @version
  * Version 0.1, 08.01.2013<br />
  */
 protected function getExpireTime(CacheKey $cacheKey)
 {
     if ($cacheKey->getTtl() !== null) {
         return $cacheKey->getTtl();
     }
     try {
         return intval($this->getConfigAttribute('ExpireTime'));
     } catch (InvalidArgumentException $e) {
         return 0;
         // cache forever
     }
 }
 public function clear(CacheKey $cacheKey = null)
 {
     $baseFolder = $this->getConfigAttribute('BaseFolder');
     $namespace = str_replace('\\', '/', $this->getConfigAttribute('Namespace'));
     // in case we do not have a cache key, remove the entire cache
     if ($cacheKey === null) {
         try {
             FilesystemManager::deleteFolder($baseFolder . '/' . $namespace, true);
             return true;
         } catch (FileException $e) {
             return false;
             // indicate, that nothing was to delete (e.g. cache not active or empty)
         }
     }
     /* @var $cacheKey AdvancedCacheKey */
     $key = $cacheKey->getKey();
     $subKey = $cacheKey->getSubKey();
     if ($key == null && $subKey == null) {
         FilesystemManager::deleteFolder($baseFolder . '/' . $namespace, true);
     } elseif ($key != null && $subKey == null) {
         // in case we have the cache key only, delete the entire structure
         // including all sub cache entries
         $key = md5($key);
         $folder = $baseFolder . '/' . $namespace . '/' . substr($key, 0, 2) . '/' . $key;
         FilesystemManager::deleteFolder($folder, true);
         return true;
     } else {
         // in case we have both cache key and cache sub key, delete the local
         // cache entry structure
         $file = $this->getCacheFile($cacheKey);
         try {
             FilesystemManager::removeFile($file);
             return true;
         } catch (FileException $e) {
             return false;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 public function clear(CacheKey $cacheKey = null)
 {
     // get memcache connection
     $mem = $this->getMemCacheConnection();
     if ($mem === false) {
         return false;
     } else {
         // clear cache
         $namespace = $this->getConfigAttribute('Namespace');
         if ($cacheKey === null) {
             if (isset($this->cacheKeyStore[$namespace])) {
                 foreach ($this->cacheKeyStore[$namespace] as $key) {
                     $mem->delete($namespace . '_' . $key);
                 }
             }
             $mem->close();
             return true;
         } else {
             $status = $mem->delete($namespace . '_' . $cacheKey->getKey());
             $mem->close();
             return $status;
         }
     }
 }
Ejemplo n.º 4
0
 public function clear(CacheKey $cacheKey = null)
 {
     // get configuration params
     $namespace = $this->getConfigAttribute('Namespace');
     $tableName = $this->getConfigAttribute('Table');
     // initialize database connection
     $db = $this->getDatabaseConnection();
     if ($cacheKey === null) {
         $delete = 'DELETE FROM `' . $tableName . '`
                    WHERE `namespace` = \'' . $namespace . '\';';
     } else {
         $delete = 'DELETE FROM `' . $tableName . '`
                    WHERE
                       `namespace` = \'' . $namespace . '\'
                       AND
                       `cachekey` = \'' . $cacheKey->getKey() . '\';';
     }
     $db->executeTextStatement($delete);
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Returns the complete cache file name. Due to filesystem performance reasons,
  * the cache key folder is separated into several parts:
  * <ul>
  * <li>base folder</li>
  * <li>namespace</li>
  * <li>2 letters of the cache key</li>
  * <li>cache key</li>
  * <li>2 letters of cache sub key (in case of an AdvancedCacheKey)</li>
  * <li>cache sub key as file name (in case of an AdvancedCacheKey)</li>
  * <li>apfc as file extension</li>
  * </ul>
  *
  * @param CacheKey $cacheKey the application's cache key.
  *
  * @return string The cache file name.
  *
  * @author Christian Achatz
  * @version
  * Version 0.1, 21.11.2008<br />
  * Version 0.2, 05.08.2010 (Enhanced cache file structure)<br />
  */
 protected function getCacheFile(CacheKey $cacheKey)
 {
     $baseFolder = $this->getConfigAttribute('BaseFolder');
     $namespace = str_replace('\\', '/', $this->getConfigAttribute('Namespace'));
     $key = md5($cacheKey->getKey());
     $folder = substr($key, 0, 2);
     if ($cacheKey instanceof AdvancedCacheKey) {
         $subKey = md5($cacheKey->getSubKey());
         $subFolder = substr($subKey, 0, 2);
         return $baseFolder . '/' . $namespace . '/' . $folder . '/' . $key . '/' . $subFolder . '/' . $subKey . '.apfc';
     } else {
         return $baseFolder . '/' . $namespace . '/' . $folder . '/' . $key . '.apfc';
     }
 }
Ejemplo n.º 6
0
 public function clear(CacheKey $cacheKey = null)
 {
     // clear cache
     $namespace = $this->getConfigAttribute('Namespace');
     if ($cacheKey === null) {
         // clear entire namespace
         foreach ($this->getCacheEntriesByNamespace($namespace) as $key) {
             apc_delete($key);
         }
         return true;
     } else {
         if ($cacheKey instanceof AdvancedCacheKey) {
             // clear al keys matching to the current main key
             foreach ($this->getCacheEntriesByNamespaceAndKey($namespace, $cacheKey->getKey()) as $key) {
                 apc_delete($key);
             }
             return true;
         } else {
             // delete dedicated entry
             return apc_delete($namespace . self::CACHE_KEY_DELIMITER . $cacheKey->getKey());
         }
     }
 }