Exemple #1
0
 /**
  *
  * Clears or purges the cache item $cacheItem.
  *
  * If $purge is true then the system will ensure the entries are removed from
  * local storage or database backend, otherwise it will use possible optimizations
  * which might only invalidate the cache entry directly or use global expiry values.
  *
  * @param $cacheItem Cache item array taken from fetchList()
  * @param $purge     Controls whether clearing/invalidation or purge is used.
  * @param $reporter  Callback which is called when the system has purged files from the system, called with filename and purge count as parameters.
  * @param $iterationSleep The amount of microseconds to sleep between each purge iteration, false means no sleep.
  * @param $iterationMax   The maximum number of items to purge in one iteration, false means use default limit.
  * @param $expiry         A timestamp which is matched against all cache items, if the modification of the cache is older than the expiry the cache is purged, false means no expiry checking.
  */
 static function clearItem($cacheItem, $purge = false, $reporter = false, $iterationSleep = false, $iterationMax = false, $expiry = false)
 {
     // Get the global expiry value if one is set and compare it with supplied $expiry value.
     // Use the largest value of the two.
     if (isset($cacheItem['expiry-key'])) {
         $key = $cacheItem['expiry-key'];
         eZExpiryHandler::registerShutdownFunction();
         $expiryHandler = eZExpiryHandler::instance();
         $keyValue = $expiryHandler->getTimestamp($key);
         if ($keyValue !== false) {
             if ($expiry !== false) {
                 $expiry = max($expiry, $keyValue);
             } else {
                 $expiry = $keyValue;
             }
         }
     }
     $cacheItem['purge'] = $purge;
     $cacheItem['reporter'] = $reporter;
     $cacheItem['iterationSleep'] = $iterationSleep;
     $cacheItem['iterationMax'] = $iterationMax;
     $cacheItem['expiry'] = $expiry;
     $functionName = false;
     if ($purge && isset($cacheItem['purge-function'])) {
         $functionName = 'purge-function';
     } else {
         if (!$purge && isset($cacheItem['function'])) {
             $functionName = 'function';
         }
     }
     if ($functionName) {
         $function = $cacheItem[$functionName];
         if (is_callable($function)) {
             call_user_func_array($function, array($cacheItem));
         } else {
             eZDebug::writeError("Could not call cache item {$functionName} for id '{$cacheItem['id']}', is it a static public function?", __METHOD__);
         }
     } else {
         if (!isset($cacheItem['path']) || strlen($cacheItem['path']) < 1) {
             eZDebug::writeError("No path specified for cache item '{$cacheItem['name']}', can not clear cache.", __METHOD__);
             return;
         }
         $cachePath = eZSys::cacheDirectory() . "/" . $cacheItem['path'];
         if (isset($cacheItem['is-clustered'])) {
             $isClustered = $cacheItem['is-clustered'];
         } else {
             $isClustered = false;
         }
         if ($isClustered) {
             $fileHandler = eZClusterFileHandler::instance($cachePath);
             if ($purge) {
                 $fileHandler->purge($reporter, $iterationSleep, $iterationMax, $expiry);
             } else {
                 $fileHandler->delete();
             }
             return;
         }
         if (is_file($cachePath)) {
             $handler = eZFileHandler::instance(false);
             $handler->unlink($cachePath);
         } else {
             eZDir::recursiveDelete($cachePath);
         }
     }
 }
 /**
  * Deletes specified file/directory.
  *
  * If a directory specified it is deleted recursively.
  *
  * \public
  * \static
  */
 function delete()
 {
     $path = $this->filePath;
     eZDebugSetting::writeDebug('kernel-clustering', "fs::delete( '{$path}' )", __METHOD__);
     eZDebug::accumulatorStart('dbfile', false, 'dbfile');
     if (is_file($path)) {
         $handler = eZFileHandler::instance(false);
         $handler->unlink($path);
         if (file_exists($path)) {
             eZDebug::writeError("File still exists after removal: '{$path}'", __METHOD__);
         }
     } elseif (is_dir($path)) {
         eZDir::recursiveDelete($path);
     }
     eZClusterFileHandler::cleanupEmptyDirectories($path);
     $this->loadMetaData(true);
     eZDebug::accumulatorStop('dbfile');
 }
 /**
  * Clears (removes) active extension cache files from the cache folder.
  * @return void
  */
 public static function clearActiveExtensionsCache()
 {
     $filesList = glob(self::CACHE_DIR . 'active_extensions_*.php');
     foreach ($filesList as $path) {
         if (is_file($path)) {
             $handler = eZFileHandler::instance(false);
             $handler->unlink($path);
         }
     }
 }