26 #require_once 'Zend/Cache/Backend/Interface.php'; 31 #require_once 'Zend/Cache/Backend.php'; 52 'file_extension' =>
'.html',
53 'index_filename' =>
'index',
54 'file_locking' =>
true,
55 'cache_file_perm' => 0600,
56 'cache_directory_perm' => 0700,
57 'debug_header' =>
false,
59 'disable_caching' =>
false 85 if (
$name ==
'tag_cache') {
89 if (
$name ==
'cache_file_umask') {
91 "'cache_file_umask' is deprecated -> please use 'cache_file_perm' instead",
95 $name =
'cache_file_perm';
97 if (
$name ==
'cache_directory_umask') {
99 "'cache_directory_umask' is deprecated -> please use 'cache_directory_perm' instead",
103 $name =
'cache_directory_perm';
122 if (
$name ==
'tag_cache') {
126 return parent::getOption(
$name);
138 public function load(
$id, $doNotTestCacheValidity =
false)
140 if ((
$id = (
string)
$id) ===
'') {
148 if ($doNotTestCacheValidity) {
149 $this->
_log(
"Zend_Cache_Backend_Static::load() : \$doNotTestCacheValidity=true is unsupported by the Static backend");
154 $fileName = $this->_options[
'index_filename'];
156 $pathName = $this->_options[
'public_dir'] . dirname(
$id);
157 $file = rtrim($pathName,
'/') .
'/' .
$fileName . $this->_options[
'file_extension'];
158 if (file_exists($file)) {
181 $fileName = $this->_options[
'index_filename'];
183 if ($this->_tagged ===
null && $tagged = $this->
getInnerCache()->
load(self::INNER_CACHE_NAME)) {
184 $this->_tagged = $tagged;
185 }
elseif (!$this->_tagged) {
188 $pathName = $this->_options[
'public_dir'] . dirname(
$id);
191 if (isset($this->_tagged[
$id])) {
194 $extension = $this->_options[
'file_extension'];
197 if (file_exists($file)) {
215 public function save(
$data,
$id, $tags = array(), $specificLifetime =
false)
217 if ($this->_options[
'disable_caching']) {
228 if ((
$id = (
string)
$id) ===
'') {
236 $fileName = $this->_options[
'index_filename'];
239 $pathName = realpath($this->_options[
'public_dir']) . dirname(
$id);
242 if (
$id ===
null || strlen(
$id) == 0) {
243 $dataUnserialized = unserialize(
$data);
244 $data = $dataUnserialized[
'data'];
246 $ext = $this->_options[
'file_extension'];
248 $file = rtrim($pathName,
'/') .
'/' .
$fileName . $ext;
249 if ($this->_options[
'file_locking']) {
254 @
chmod($file, $this->
_octdec($this->_options[
'cache_file_perm']));
256 if ($this->_tagged ===
null && $tagged = $this->
getInnerCache()->
load(self::INNER_CACHE_NAME)) {
257 $this->_tagged = $tagged;
258 }
elseif ($this->_tagged ===
null) {
259 $this->_tagged = array();
261 if (!isset($this->_tagged[
$id])) {
262 $this->_tagged[
$id] = array();
264 if (!isset($this->_tagged[
$id][
'tags'])) {
265 $this->_tagged[
$id][
'tags'] = array();
267 $this->_tagged[
$id][
'tags'] = array_unique(array_merge($this->_tagged[
$id][
'tags'], $tags));
268 $this->_tagged[
$id][
'extension'] = $ext;
269 $this->
getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
279 $oldUmask = umask(0);
280 if ( !@
mkdir(
$path, $this->
_octdec($this->_options[
'cache_directory_perm']),
true)) {
281 $lastErr = error_get_last();
300 return preg_match(
"/a:2:\{i:0;s:\d+:\"/",
$data);
309 public function remove(
$id)
315 if ($this->_tagged ===
null && $tagged = $this->
getInnerCache()->
load(self::INNER_CACHE_NAME)) {
316 $this->_tagged = $tagged;
317 }
elseif (!$this->_tagged) {
320 if (isset($this->_tagged[
$id])) {
323 $extension = $this->_options[
'file_extension'];
326 $fileName = $this->_options[
'index_filename'];
328 $pathName = $this->_options[
'public_dir'] . dirname(
$id);
330 if (!file_exists($file)) {
351 $fileName = $this->_options[
'index_filename'];
353 $pathName = $this->_options[
'public_dir'] . dirname(
$id);
354 $file = $pathName .
'/' .
$fileName . $this->_options[
'file_extension'];
355 $directory = $pathName .
'/' .
$fileName;
356 if (file_exists($directory)) {
361 foreach (
new DirectoryIterator($directory) as $file) {
362 if (
true === $file->isFile()) {
363 if (
false ===
unlink($file->getPathName())) {
371 if (file_exists($file)) {
405 throw new Zend_Exception(
'Cannot use tag matching modes as no tags were defined');
407 if ($this->_tagged ===
null && $tagged = $this->
getInnerCache()->
load(self::INNER_CACHE_NAME)) {
408 $this->_tagged = $tagged;
409 }
elseif (!$this->_tagged) {
412 foreach ($tags as $tag) {
413 $urls = array_keys($this->_tagged);
415 if (isset($this->_tagged[
$url][
'tags']) && in_array($tag, $this->_tagged[
$url][
'tags'])) {
417 unset($this->_tagged[
$url]);
421 $this->
getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
425 if ($this->_tagged ===
null) {
426 $tagged = $this->
getInnerCache()->load(self::INNER_CACHE_NAME);
427 $this->_tagged = $tagged;
429 if ($this->_tagged ===
null || empty($this->_tagged)) {
432 $urls = array_keys($this->_tagged);
435 unset($this->_tagged[
$url]);
437 $this->
getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
441 $this->
_log(
"Zend_Cache_Backend_Static : Selected Cleaning Mode Currently Unsupported By This Backend");
445 throw new Zend_Exception(
'Cannot use tag matching modes as no tags were defined');
447 if ($this->_tagged ===
null) {
448 $tagged = $this->
getInnerCache()->load(self::INNER_CACHE_NAME);
449 $this->_tagged = $tagged;
451 if ($this->_tagged ===
null || empty($this->_tagged)) {
454 $urls = array_keys($this->_tagged);
456 $difference = array_diff($tags, $this->_tagged[
$url][
'tags']);
457 if (count($tags) == count($difference)) {
459 unset($this->_tagged[
$url]);
462 $this->
getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
483 $this->_tagCache =
$cache;
484 $this->_options[
'tag_cache'] =
$cache;
494 if ($this->_tagCache ===
null) {
509 $base = realpath($this->_options[
'public_dir']);
520 return $_SERVER[
'REQUEST_URI'];
535 if (!is_string($string)) {
540 if (substr($string, 0, 9) ==
'internal-') {
546 '/^(?:\/(?:(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*\'()\[\]:@&=+$,;])*)?)+$/',
563 if (is_string($val) && decoct(octdec($val)) == $val) {
577 return pack(
'H*',
$id);
elseif(isset( $params[ 'redirect_parent']))
setInnerCache(Zend_Cache_Core $cache)
save($data, $id, $tags=array(), $specificLifetime=false)
_log($message, $priority=4)
static _validateIdOrTag($string)
const CLEANING_MODE_NOT_MATCHING_TAG
load($id, $doNotTestCacheValidity=false)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
clean($mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array())
static throwException($msg, Exception $e=null)
mkdir($pathname, $mode=0777, $recursive=false, $context=null)
const CLEANING_MODE_MATCHING_ANY_TAG
const CLEANING_MODE_MATCHING_TAG
_createDirectoriesFor($path)
if(!isset($_GET['name'])) $name