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; }
public function clear(CacheKey $cacheKey = null) { $baseFolder = $this->getConfigAttribute('BaseFolder'); if ($cacheKey === null) { return FilesystemManager::deleteFolder($baseFolder, true); } else { $cacheFile = $this->getCacheFile($cacheKey); try { return FilesystemManager::removeFile($cacheFile); } catch (FileException $e) { return false; } } }