diff options
Diffstat (limited to 'libs/Zend/Cache/Core.php')
-rw-r--r-- | libs/Zend/Cache/Core.php | 139 |
1 files changed, 106 insertions, 33 deletions
diff --git a/libs/Zend/Cache/Core.php b/libs/Zend/Cache/Core.php index 361fc3e75c..680d4d8028 100644 --- a/libs/Zend/Cache/Core.php +++ b/libs/Zend/Cache/Core.php @@ -14,20 +14,26 @@ * * @category Zend * @package Zend_Cache - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Core.php 18255 2009-09-18 17:26:32Z padraic $ + * @version $Id: Core.php 21293 2010-03-02 10:26:32Z mabe $ */ /** * @package Zend_Cache - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Cache_Core { /** + * Messages + */ + const BACKEND_NOT_SUPPORTS_TAG = 'tags are not supported by the current backend'; + const BACKEND_NOT_IMPLEMENTS_EXTENDED_IF = 'Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'; + + /** * Backend Object * * @var object $_backend @@ -256,6 +262,9 @@ class Zend_Cache_Core if (!is_string($name) || !array_key_exists($name, $this->_options)) { Zend_Cache::throwException("Incorrect option name : $name"); } + if ($name == 'lifetime' && empty($value)) { + $value = null; + } $this->_options[$name] = $value; } @@ -307,7 +316,7 @@ class Zend_Cache_Core * Test if a cache is available for the given id * * @param string $id Cache id - * @return boolean True is a cache is available, false else + * @return int|false Last modified time of cache entry if it is available, false otherwise */ public function test($id) { @@ -463,12 +472,26 @@ class Zend_Cache_Core public function getIdsMatchingTags($tags = array()) { if (!$this->_extendedBackend) { - Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'); + Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF); } if (!($this->_backendCapabilities['tags'])) { - Zend_Cache::throwException('tags are not supported by the current backend'); + Zend_Cache::throwException(self::BACKEND_NOT_SUPPORT_TAG); } - return $this->_backend->getIdsMatchingTags($tags); + + $ids = $this->_backend->getIdsMatchingTags($tags); + + // we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600) + if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') { + $prefix = & $this->_options['cache_id_prefix']; + $prefixLen = strlen($prefix); + foreach ($ids as &$id) { + if (strpos($id, $prefix) === 0) { + $id = substr($id, $prefixLen); + } + } + } + + return $ids; } /** @@ -482,12 +505,59 @@ class Zend_Cache_Core public function getIdsNotMatchingTags($tags = array()) { if (!$this->_extendedBackend) { - Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'); + Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF); + } + if (!($this->_backendCapabilities['tags'])) { + Zend_Cache::throwException(self::BACKEND_NOT_SUPPORT_TAG); + } + + $ids = $this->_backend->getIdsNotMatchingTags($tags); + + // we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600) + if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') { + $prefix = & $this->_options['cache_id_prefix']; + $prefixLen = strlen($prefix); + foreach ($ids as &$id) { + if (strpos($id, $prefix) === 0) { + $id = substr($id, $prefixLen); + } + } + } + + return $ids; + } + + /** + * Return an array of stored cache ids which match any given tags + * + * In case of multiple tags, a logical OR is made between tags + * + * @param array $tags array of tags + * @return array array of matching any cache ids (string) + */ + public function getIdsMatchingAnyTags($tags = array()) + { + if (!$this->_extendedBackend) { + Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF); } if (!($this->_backendCapabilities['tags'])) { - Zend_Cache::throwException('tags are not supported by the current backend'); + Zend_Cache::throwException(self::BACKEND_NOT_SUPPORT_TAG); + } + + $ids = $this->_backend->getIdsMatchingAnyTags($tags); + + // we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600) + if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') { + $prefix = & $this->_options['cache_id_prefix']; + $prefixLen = strlen($prefix); + foreach ($ids as &$id) { + if (strpos($id, $prefix) === 0) { + $id = substr($id, $prefixLen); + } + } } - return $this->_backend->getIdsNotMatchingTags($tags); + + return $ids; } /** @@ -498,20 +568,23 @@ class Zend_Cache_Core public function getIds() { if (!$this->_extendedBackend) { - Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'); - } - $array = $this->_backend->getIds(); - if ((!isset($this->_options['cache_id_prefix'])) || ($this->_options['cache_id_prefix'] == '')) return $array; - // we need to remove cache_id_prefix from ids (see #ZF-6178) - $res = array(); - while (list(,$id) = each($array)) { - if (strpos($id, $this->_options['cache_id_prefix']) === 0) { - $res[] = preg_replace("~^{$this->_options['cache_id_prefix']}~", '', $id); - } else { - $res[] = $id; - } - } - return $res; + Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF); + } + + $ids = $this->_backend->getIds(); + + // we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600) + if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') { + $prefix = & $this->_options['cache_id_prefix']; + $prefixLen = strlen($prefix); + foreach ($ids as &$id) { + if (strpos($id, $prefix) === 0) { + $id = substr($id, $prefixLen); + } + } + } + + return $ids; } /** @@ -522,10 +595,10 @@ class Zend_Cache_Core public function getTags() { if (!$this->_extendedBackend) { - Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'); + Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF); } if (!($this->_backendCapabilities['tags'])) { - Zend_Cache::throwException('tags are not supported by the current backend'); + Zend_Cache::throwException(self::BACKEND_NOT_SUPPORT_TAG); } return $this->_backend->getTags(); } @@ -538,11 +611,11 @@ class Zend_Cache_Core public function getFillingPercentage() { if (!$this->_extendedBackend) { - Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'); + Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF); } return $this->_backend->getFillingPercentage(); } - + /** * Return an array of metadatas for the given cache id * @@ -556,8 +629,8 @@ class Zend_Cache_Core */ public function getMetadatas($id) { - if (!$this->_extendedBackend) { - Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'); + if (!$this->_extendedBackend) { + Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF); } $id = $this->_id($id); // cache id may need prefix return $this->_backend->getMetadatas($id); @@ -573,7 +646,7 @@ class Zend_Cache_Core public function touch($id, $extraLifetime) { if (!$this->_extendedBackend) { - Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'); + Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF); } $id = $this->_id($id); // cache id may need prefix return $this->_backend->touch($id, $extraLifetime); @@ -596,7 +669,7 @@ class Zend_Cache_Core if (substr($string, 0, 9) == 'internal-') { Zend_Cache::throwException('"internal-*" ids or tags are reserved'); } - if (!preg_match('~^[\w]+$~D', $string)) { + if (!preg_match('~^[a-zA-Z0-9_]+$~D', $string)) { Zend_Cache::throwException("Invalid id or tag '$string' : must use only [a-zA-Z0-9_]"); } } @@ -640,7 +713,7 @@ class Zend_Cache_Core } // Create a default logger to the standard output stream - require_once 'Zend/Log/Writer/Stream.php'; + // require_once 'Zend/Log/Writer/Stream.php'; $logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output')); $this->_options['logger'] = $logger; } |