diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:45:36 +0400 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:45:36 +0400 |
commit | 7e1b5d6b762340cbff1bb928d15815980c7649a7 (patch) | |
tree | e07da179b9e1372866d2349777bd1cc6b4c9e8cf /libs/Zend/Cache | |
parent | 999f46479294713104c962bfe7469e9b6e7a4bbf (diff) | |
parent | c98ea06f2cccec81c6ccce49162a583494e44d91 (diff) |
Diffstat (limited to 'libs/Zend/Cache')
25 files changed, 1755 insertions, 331 deletions
diff --git a/libs/Zend/Cache/Backend.php b/libs/Zend/Cache/Backend.php index 052181972f..f71dae135a 100644 --- a/libs/Zend/Cache/Backend.php +++ b/libs/Zend/Cache/Backend.php @@ -15,16 +15,16 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: Backend.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Backend.php 20882 2010-02-03 18:19:44Z matthew $ */ /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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_Backend @@ -140,77 +140,77 @@ class Zend_Cache_Backend { return true; } - + /** * Determine system TMP directory and detect if we have read access * - * inspired from Zend_File_Transfer_Adapter_Abstract + * inspired from Zend_File_Transfer_Adapter_Abstract * * @return string * @throws Zend_Cache_Exception if unable to determine directory */ public function getTmpDir() { - $tmpdir = array(); + $tmpdir = array(); foreach (array($_ENV, $_SERVER) as $tab) { - foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) { - if (isset($tab[$key])) { - if (($key == 'windir') or ($key == 'SystemRoot')) { + foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) { + if (isset($tab[$key])) { + if (($key == 'windir') or ($key == 'SystemRoot')) { $dir = realpath($tab[$key] . '\\temp'); } else { - $dir = realpath($tab[$key]); + $dir = realpath($tab[$key]); + } + if ($this->_isGoodTmpDir($dir)) { + return $dir; } - if ($this->_isGoodTmpDir($dir)) { - return $dir; - } - } - } + } + } } $upload = ini_get('upload_tmp_dir'); if ($upload) { $dir = realpath($upload); - if ($this->_isGoodTmpDir($dir)) { - return $dir; - } + if ($this->_isGoodTmpDir($dir)) { + return $dir; + } } if (function_exists('sys_get_temp_dir')) { $dir = sys_get_temp_dir(); - if ($this->_isGoodTmpDir($dir)) { - return $dir; - } + if ($this->_isGoodTmpDir($dir)) { + return $dir; + } } // Attemp to detect by creating a temporary file $tempFile = tempnam(md5(uniqid(rand(), TRUE)), ''); if ($tempFile) { - $dir = realpath(dirname($tempFile)); + $dir = realpath(dirname($tempFile)); unlink($tempFile); if ($this->_isGoodTmpDir($dir)) { return $dir; } } if ($this->_isGoodTmpDir('/tmp')) { - return '/tmp'; + return '/tmp'; } if ($this->_isGoodTmpDir('\\temp')) { - return '\\temp'; + return '\\temp'; } Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually'); } - + /** * Verify if the given temporary directory is readable and writable - * + * * @param $dir temporary directory * @return boolean true if the directory is ok */ protected function _isGoodTmpDir($dir) { - if (is_readable($dir)) { - if (is_writable($dir)) { - return true; - } - } - return false; + if (is_readable($dir)) { + if (is_writable($dir)) { + return true; + } + } + return false; } /** @@ -226,23 +226,17 @@ class Zend_Cache_Backend if (!isset($this->_directives['logging']) || !$this->_directives['logging']) { return; } - try { - /** - * @see Zend_Log - */ - require_once 'Zend/Log.php'; - } catch (Zend_Exception $e) { - Zend_Cache::throwException('Logging feature is enabled but the Zend_Log class is not available'); - } + if (isset($this->_directives['logger'])) { if ($this->_directives['logger'] instanceof Zend_Log) { return; - } else { - Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.'); } + Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.'); } + // Create a default logger to the standard output stream - require_once 'Zend/Log/Writer/Stream.php'; + // require_once 'Zend/Log.php'; + // require_once 'Zend/Log/Writer/Stream.php'; $logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output')); $this->_directives['logger'] = $logger; } @@ -261,7 +255,7 @@ class Zend_Cache_Backend } if (!isset($this->_directives['logger'])) { - Zend_Cache::throwException('Logging is enabled but logger is not set.'); + Zend_Cache::throwException('Logging is enabled but logger is not set.'); } $logger = $this->_directives['logger']; if (!$logger instanceof Zend_Log) { diff --git a/libs/Zend/Cache/Backend/Apc.php b/libs/Zend/Cache/Backend/Apc.php index fd99ae45ef..e25bd397bb 100644 --- a/libs/Zend/Cache/Backend/Apc.php +++ b/libs/Zend/Cache/Backend/Apc.php @@ -15,27 +15,27 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: Apc.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Apc.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend/ExtendedInterface.php'; +// require_once 'Zend/Cache/Backend/ExtendedInterface.php'; /** * @see Zend_Cache_Backend */ -require_once 'Zend/Cache/Backend.php'; +// require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface @@ -166,18 +166,18 @@ class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Ba * Return true if the automatic cleaning is available for the backend * * DEPRECATED : use getCapabilities() instead - * - * @deprecated + * + * @deprecated * @return boolean */ public function isAutomaticCleaningAvailable() { return false; } - + /** * Return the filling percentage of the backend storage - * + * * @throws Zend_Cache_Exception * @return int integer between 0 and 100 */ @@ -195,21 +195,21 @@ class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Ba } return ((int) (100. * ($memUsed / $memSize))); } - + /** * Return an array of stored tags * * @return array array of stored tags (string) */ public function getTags() - { + { $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND); return array(); } - + /** * Return an array of stored cache ids which match given tags - * + * * In case of multiple tags, a logical AND is made between tags * * @param array $tags array of tags @@ -218,26 +218,26 @@ class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Ba public function getIdsMatchingTags($tags = array()) { $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND); - return array(); + return array(); } /** * Return an array of stored cache ids which don't match given tags - * + * * In case of multiple tags, a logical OR is made between tags * * @param array $tags array of tags * @return array array of not matching cache ids (string) - */ + */ public function getIdsNotMatchingTags($tags = array()) { $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND); - return array(); + return array(); } - + /** * Return an array of stored cache ids which match any given tags - * + * * In case of multiple tags, a logical AND is made between tags * * @param array $tags array of tags @@ -246,12 +246,12 @@ class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Ba public function getIdsMatchingAnyTags($tags = array()) { $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND); - return array(); + return array(); } - + /** * Return an array of stored cache ids - * + * * @return array array of stored cache ids (string) */ public function getIds() @@ -264,7 +264,7 @@ class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Ba } return $res; } - + /** * Return an array of metadatas for the given cache id * @@ -272,7 +272,7 @@ class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Ba * - expire : the expire timestamp * - tags : a string array of tags * - mtime : timestamp of last modification time - * + * * @param string $id cache id * @return array array of metadatas (false if the cache id is not found) */ @@ -294,9 +294,9 @@ class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Ba 'mtime' => $mtime ); } - return false; + return false; } - + /** * Give (if possible) an extra lifetime to the given cache id * @@ -318,17 +318,17 @@ class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Ba $lifetime = $tmp[2]; $newLifetime = $lifetime - (time() - $mtime) + $extraLifetime; if ($newLifetime <=0) { - return false; + return false; } apc_store($id, array($data, time(), $newLifetime), $newLifetime); return true; } return false; } - + /** * Return an associative array of capabilities (booleans) of the backend - * + * * The array must include these keys : * - automatic_cleaning (is automating cleaning necessary) * - tags (are tags supported) @@ -337,7 +337,7 @@ class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Ba * - priority does the backend deal with priority when saving * - infinite_lifetime (is infinite lifetime can work with this backend) * - get_list (is it possible to get the list of cache ids and the complete list of tags) - * + * * @return array associative of with capabilities */ public function getCapabilities() diff --git a/libs/Zend/Cache/Backend/BlackHole.php b/libs/Zend/Cache/Backend/BlackHole.php new file mode 100644 index 0000000000..3eb382eca2 --- /dev/null +++ b/libs/Zend/Cache/Backend/BlackHole.php @@ -0,0 +1,250 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Cache + * @subpackage Zend_Cache_Backend + * @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: BlackHole.php 17867 2009-08-28 09:42:11Z yoshida@zend.co.jp $ + */ + +/** + * @see Zend_Cache_Backend_Interface + */ +// require_once 'Zend/Cache/Backend/ExtendedInterface.php'; + +/** + * @see Zend_Cache_Backend + */ +// require_once 'Zend/Cache/Backend.php'; + +/** + * @package Zend_Cache + * @subpackage Zend_Cache_Backend + * @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_Backend_BlackHole + extends Zend_Cache_Backend + implements Zend_Cache_Backend_ExtendedInterface +{ + /** + * Test if a cache is available for the given id and (if yes) return it (false else) + * + * @param string $id cache id + * @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested + * @return string|false cached datas + */ + public function load($id, $doNotTestCacheValidity = false) + { + return false; + } + + /** + * Test if a cache is available or not (for the given id) + * + * @param string $id cache id + * @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record + */ + public function test($id) + { + return false; + } + + /** + * Save some string datas into a cache record + * + * Note : $data is always "string" (serialization is done by the + * core not by the backend) + * + * @param string $data Datas to cache + * @param string $id Cache id + * @param array $tags Array of strings, the cache record will be tagged by each string entry + * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) + * @return boolean true if no problem + */ + public function save($data, $id, $tags = array(), $specificLifetime = false) + { + return true; + } + + /** + * Remove a cache record + * + * @param string $id cache id + * @return boolean true if no problem + */ + public function remove($id) + { + return true; + } + + /** + * Clean some cache records + * + * Available modes are : + * 'all' (default) => remove all cache entries ($tags is not used) + * 'old' => remove too old cache entries ($tags is not used) + * 'matchingTag' => remove cache entries matching all given tags + * ($tags can be an array of strings or a single string) + * 'notMatchingTag' => remove cache entries not matching one of the given tags + * ($tags can be an array of strings or a single string) + * 'matchingAnyTag' => remove cache entries matching any given tags + * ($tags can be an array of strings or a single string) + * + * @param string $mode clean mode + * @param tags array $tags array of tags + * @return boolean true if no problem + */ + public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) + { + return true; + } + + /** + * Return an array of stored cache ids + * + * @return array array of stored cache ids (string) + */ + public function getIds() + { + return array(); + } + + /** + * Return an array of stored tags + * + * @return array array of stored tags (string) + */ + public function getTags() + { + return array(); + } + + /** + * Return an array of stored cache ids which match given tags + * + * In case of multiple tags, a logical AND is made between tags + * + * @param array $tags array of tags + * @return array array of matching cache ids (string) + */ + public function getIdsMatchingTags($tags = array()) + { + return array(); + } + + /** + * Return an array of stored cache ids which don't match given tags + * + * In case of multiple tags, a logical OR is made between tags + * + * @param array $tags array of tags + * @return array array of not matching cache ids (string) + */ + public function getIdsNotMatchingTags($tags = array()) + { + return array(); + } + + /** + * Return an array of stored cache ids which match any given tags + * + * In case of multiple tags, a logical AND is made between tags + * + * @param array $tags array of tags + * @return array array of any matching cache ids (string) + */ + public function getIdsMatchingAnyTags($tags = array()) + { + return array(); + } + + /** + * Return the filling percentage of the backend storage + * + * @return int integer between 0 and 100 + * @throws Zend_Cache_Exception + */ + public function getFillingPercentage() + { + return 0; + } + + /** + * Return an array of metadatas for the given cache id + * + * The array must include these keys : + * - expire : the expire timestamp + * - tags : a string array of tags + * - mtime : timestamp of last modification time + * + * @param string $id cache id + * @return array array of metadatas (false if the cache id is not found) + */ + public function getMetadatas($id) + { + return false; + } + + /** + * Give (if possible) an extra lifetime to the given cache id + * + * @param string $id cache id + * @param int $extraLifetime + * @return boolean true if ok + */ + public function touch($id, $extraLifetime) + { + return false; + } + + /** + * Return an associative array of capabilities (booleans) of the backend + * + * The array must include these keys : + * - automatic_cleaning (is automating cleaning necessary) + * - tags (are tags supported) + * - expired_read (is it possible to read expired cache records + * (for doNotTestCacheValidity option for example)) + * - priority does the backend deal with priority when saving + * - infinite_lifetime (is infinite lifetime can work with this backend) + * - get_list (is it possible to get the list of cache ids and the complete list of tags) + * + * @return array associative of with capabilities + */ + public function getCapabilities() + { + return array( + 'automatic_cleaning' => true, + 'tags' => true, + 'expired_read' => true, + 'priority' => true, + 'infinite_lifetime' => true, + 'get_list' => true, + ); + } + + /** + * PUBLIC METHOD FOR UNIT TESTING ONLY ! + * + * Force a cache record to expire + * + * @param string $id cache id + */ + public function ___expire($id) + { + } +} diff --git a/libs/Zend/Cache/Backend/ExtendedInterface.php b/libs/Zend/Cache/Backend/ExtendedInterface.php index 22e559b25b..f24ecc1091 100644 --- a/libs/Zend/Cache/Backend/ExtendedInterface.php +++ b/libs/Zend/Cache/Backend/ExtendedInterface.php @@ -15,20 +15,20 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: ExtendedInterface.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: ExtendedInterface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend/Interface.php'; +// require_once 'Zend/Cache/Backend/Interface.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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 */ interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interface @@ -36,21 +36,21 @@ interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interf /** * Return an array of stored cache ids - * + * * @return array array of stored cache ids (string) */ public function getIds(); - + /** * Return an array of stored tags * * @return array array of stored tags (string) */ public function getTags(); - + /** * Return an array of stored cache ids which match given tags - * + * * In case of multiple tags, a logical AND is made between tags * * @param array $tags array of tags @@ -60,24 +60,24 @@ interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interf /** * Return an array of stored cache ids which don't match given tags - * + * * In case of multiple tags, a logical OR is made between tags * * @param array $tags array of tags * @return array array of not matching cache ids (string) - */ + */ public function getIdsNotMatchingTags($tags = array()); /** * Return an array of stored cache ids which match any given tags - * + * * In case of multiple tags, a logical AND is made between tags * * @param array $tags array of tags * @return array array of any matching cache ids (string) */ public function getIdsMatchingAnyTags($tags = array()); - + /** * Return the filling percentage of the backend storage * @@ -92,12 +92,12 @@ interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interf * - expire : the expire timestamp * - tags : a string array of tags * - mtime : timestamp of last modification time - * + * * @param string $id cache id * @return array array of metadatas (false if the cache id is not found) */ public function getMetadatas($id); - + /** * Give (if possible) an extra lifetime to the given cache id * @@ -106,10 +106,10 @@ interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interf * @return boolean true if ok */ public function touch($id, $extraLifetime); - + /** * Return an associative array of capabilities (booleans) of the backend - * + * * The array must include these keys : * - automatic_cleaning (is automating cleaning necessary) * - tags (are tags supported) @@ -118,9 +118,9 @@ interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interf * - priority does the backend deal with priority when saving * - infinite_lifetime (is infinite lifetime can work with this backend) * - get_list (is it possible to get the list of cache ids and the complete list of tags) - * + * * @return array associative of with capabilities */ public function getCapabilities(); - + } diff --git a/libs/Zend/Cache/Backend/File.php b/libs/Zend/Cache/Backend/File.php index 51e2697ad9..eeddfa5b80 100644 --- a/libs/Zend/Cache/Backend/File.php +++ b/libs/Zend/Cache/Backend/File.php @@ -15,26 +15,26 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: File.php 17868 2009-08-28 09:46:30Z yoshida@zend.co.jp $ + * @version $Id: File.php 21642 2010-03-25 17:07:02Z mabe $ */ /** * @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend/ExtendedInterface.php'; +// require_once 'Zend/Cache/Backend/ExtendedInterface.php'; /** * @see Zend_Cache_Backend */ -require_once 'Zend/Cache/Backend.php'; +// require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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_Backend_File extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface @@ -123,8 +123,8 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B $this->setCacheDir(self::getTmpDir() . DIRECTORY_SEPARATOR, false); } if (isset($this->_options['file_name_prefix'])) { // particular case for this option - if (!preg_match('~^[\w]+$~', $this->_options['file_name_prefix'])) { - Zend_Cache::throwException('Invalid file_name_prefix : must use only [a-zA-A0-9_]'); + if (!preg_match('~^[a-zA-Z0-9_]+$~D', $this->_options['file_name_prefix'])) { + Zend_Cache::throwException('Invalid file_name_prefix : must use only [a-zA-Z0-9_]'); } } if ($this->_options['metadatas_array_max_size'] < 10) { @@ -647,6 +647,7 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B $prefix = $this->_options['file_name_prefix']; $glob = @glob($dir . $prefix . '--*'); if ($glob === false) { + // On some systems it is impossible to distinguish between empty match and an error. return true; } foreach ($glob as $file) { @@ -739,7 +740,8 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B $prefix = $this->_options['file_name_prefix']; $glob = @glob($dir . $prefix . '--*'); if ($glob === false) { - return true; + // On some systems it is impossible to distinguish between empty match and an error. + return array(); } foreach ($glob as $file) { if (is_file($file)) { @@ -802,7 +804,12 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B } if ((is_dir($file)) and ($this->_options['hashed_directory_level']>0)) { // Recursive call - $result = array_unique(array_merge($result, $this->_get($file . DIRECTORY_SEPARATOR, $mode, $tags))); + $recursiveRs = $this->_get($file . DIRECTORY_SEPARATOR, $mode, $tags); + if ($recursiveRs === false) { + $this->_log('Zend_Cache_Backend_File::_get() / recursive call : can\'t list entries of "'.$file.'"'); + } else { + $result = array_unique(array_merge($result, $recursiveRs)); + } } } return array_unique($result); diff --git a/libs/Zend/Cache/Backend/Interface.php b/libs/Zend/Cache/Backend/Interface.php index f2878f95ae..3e8c7d1211 100644 --- a/libs/Zend/Cache/Backend/Interface.php +++ b/libs/Zend/Cache/Backend/Interface.php @@ -15,16 +15,16 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: Interface.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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 */ interface Zend_Cache_Backend_Interface diff --git a/libs/Zend/Cache/Backend/Memcached.php b/libs/Zend/Cache/Backend/Memcached.php index 86bbca3a1c..3c29bcce67 100644 --- a/libs/Zend/Cache/Backend/Memcached.php +++ b/libs/Zend/Cache/Backend/Memcached.php @@ -15,27 +15,27 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: Memcached.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Memcached.php 22208 2010-05-20 16:59:02Z mabe $ */ /** * @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend/ExtendedInterface.php'; +// require_once 'Zend/Cache/Backend/ExtendedInterface.php'; /** * @see Zend_Cache_Backend */ -require_once 'Zend/Cache/Backend.php'; +// require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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_Backend_Memcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface @@ -155,16 +155,16 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca $server['failure_callback'] = self::DEFAULT_FAILURE_CALLBACK; } if ($this->_options['compatibility']) { - // No status for compatibility mode (#ZF-5887) - $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'], + // No status for compatibility mode (#ZF-5887) + $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval']); - } else { - $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'], + } else { + $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval'], $server['status'], $server['failure_callback']); - } + } } } @@ -178,7 +178,7 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca public function load($id, $doNotTestCacheValidity = false) { $tmp = $this->_memcache->get($id); - if (is_array($tmp)) { + if (is_array($tmp) && isset($tmp[0])) { return $tmp[0]; } return false; @@ -219,13 +219,14 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca } else { $flag = 0; } - // #ZF-5702 : we try add() first becase set() seems to be slower - if (!($result = $this->_memcache->add($id, array($data, time(), $lifetime), $flag, $lifetime))) { - $result = $this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime); - } + + // ZF-8856: using set because add needs a second request if item already exists + $result = @$this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime); + if (count($tags) > 0) { - $this->_log("Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend"); + $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND); } + return $result; } @@ -237,7 +238,7 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca */ public function remove($id) { - return $this->_memcache->delete($id); + return $this->_memcache->delete($id, 0); } /** @@ -380,25 +381,26 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca { $mems = $this->_memcache->getExtendedStats(); - $memSize = 0; - $memUsed = 0; + $memSize = null; + $memUsed = null; foreach ($mems as $key => $mem) { - if ($mem === false) { - Zend_Cache::throwException('can\'t get stat from ' . $key); - } else { - $eachSize = $mem['limit_maxbytes']; - if ($eachSize == 0) { - Zend_Cache::throwException('can\'t get memory size from ' . $key); - } - - $eachUsed = $mem['bytes']; - if ($eachUsed > $eachSize) { - $eachUsed = $eachSize; - } - - $memSize += $eachSize; - $memUsed += $eachUsed; - } + if ($mem === false) { + $this->_log('can\'t get stat from ' . $key); + continue; + } + + $eachSize = $mem['limit_maxbytes']; + $eachUsed = $mem['bytes']; + if ($eachUsed > $eachSize) { + $eachUsed = $eachSize; + } + + $memSize += $eachSize; + $memUsed += $eachUsed; + } + + if ($memSize === null || $memUsed === null) { + Zend_Cache::throwException('Can\'t get filling percentage'); } return ((int) (100. * ($memUsed / $memSize))); @@ -466,7 +468,7 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca } // #ZF-5702 : we try replace() first becase set() seems to be slower if (!($result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $flag, $newLifetime))) { - $result = $this->_memcache->set($id, array($data, time(), $newLifetime), $flag, $newLifetime); + $result = $this->_memcache->set($id, array($data, time(), $newLifetime), $flag, $newLifetime); } return $result; } diff --git a/libs/Zend/Cache/Backend/Sqlite.php b/libs/Zend/Cache/Backend/Sqlite.php index 7430d7303b..3bb5ba91e3 100644 --- a/libs/Zend/Cache/Backend/Sqlite.php +++ b/libs/Zend/Cache/Backend/Sqlite.php @@ -15,26 +15,26 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: Sqlite.php 17868 2009-08-28 09:46:30Z yoshida@zend.co.jp $ + * @version $Id: Sqlite.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend/ExtendedInterface.php'; +// require_once 'Zend/Cache/Backend/ExtendedInterface.php'; /** * @see Zend_Cache_Backend */ -require_once 'Zend/Cache/Backend.php'; +// require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface diff --git a/libs/Zend/Cache/Backend/Static.php b/libs/Zend/Cache/Backend/Static.php new file mode 100644 index 0000000000..19d83d5fd4 --- /dev/null +++ b/libs/Zend/Cache/Backend/Static.php @@ -0,0 +1,558 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Cache + * @subpackage Zend_Cache_Backend + * @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: BlackHole.php 17867 2009-08-28 09:42:11Z yoshida@zend.co.jp $ + */ + +/** + * @see Zend_Cache_Backend_Interface + */ +// require_once 'Zend/Cache/Backend/Interface.php'; + +/** + * @see Zend_Cache_Backend + */ +// require_once 'Zend/Cache/Backend.php'; + +/** + * @package Zend_Cache + * @subpackage Zend_Cache_Backend + * @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_Backend_Static + extends Zend_Cache_Backend + implements Zend_Cache_Backend_Interface +{ + const INNER_CACHE_NAME = 'zend_cache_backend_static_tagcache'; + + /** + * Static backend options + * @var array + */ + protected $_options = array( + 'public_dir' => null, + 'sub_dir' => 'html', + 'file_extension' => '.html', + 'index_filename' => 'index', + 'file_locking' => true, + 'cache_file_umask' => 0600, + 'cache_directory_umask' => 0700, + 'debug_header' => false, + 'tag_cache' => null, + 'disable_caching' => false + ); + + /** + * Cache for handling tags + * @var Zend_Cache_Core + */ + protected $_tagCache = null; + + /** + * Tagged items + * @var array + */ + protected $_tagged = null; + + /** + * Interceptor child method to handle the case where an Inner + * Cache object is being set since it's not supported by the + * standard backend interface + * + * @param string $name + * @param mixed $value + * @return Zend_Cache_Backend_Static + */ + public function setOption($name, $value) + { + if ($name == 'tag_cache') { + $this->setInnerCache($value); + } else { + parent::setOption($name, $value); + } + return $this; + } + + /** + * Retrieve any option via interception of the parent's statically held + * options including the local option for a tag cache. + * + * @param string $name + * @return mixed + */ + public function getOption($name) + { + if ($name == 'tag_cache') { + return $this->getInnerCache(); + } else { + if (in_array($name, $this->_options)) { + return $this->_options[$name]; + } + if ($name == 'lifetime') { + return parent::getLifetime(); + } + return null; + } + } + + /** + * Test if a cache is available for the given id and (if yes) return it (false else) + * + * Note : return value is always "string" (unserialization is done by the core not by the backend) + * + * @param string $id Cache id + * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested + * @return string|false cached datas + */ + public function load($id, $doNotTestCacheValidity = false) + { + if (empty($id)) { + $id = $this->_detectId(); + } else { + $id = $this->_decodeId($id); + } + if (!$this->_verifyPath($id)) { + Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path'); + } + if ($doNotTestCacheValidity) { + $this->_log("Zend_Cache_Backend_Static::load() : \$doNotTestCacheValidity=true is unsupported by the Static backend"); + } + + $fileName = basename($id); + if (empty($fileName)) { + $fileName = $this->_options['index_filename']; + } + $pathName = $this->_options['public_dir'] . dirname($id); + $file = rtrim($pathName, '/') . '/' . $fileName . $this->_options['file_extension']; + if (file_exists($file)) { + $content = file_get_contents($file); + return $content; + } + + return false; + } + + /** + * Test if a cache is available or not (for the given id) + * + * @param string $id cache id + * @return bool + */ + public function test($id) + { + $id = $this->_decodeId($id); + if (!$this->_verifyPath($id)) { + Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path'); + } + + $fileName = basename($id); + if (empty($fileName)) { + $fileName = $this->_options['index_filename']; + } + if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { + $this->_tagged = $tagged; + } elseif (!$this->_tagged) { + return false; + } + $pathName = $this->_options['public_dir'] . dirname($id); + + // Switch extension if needed + if (isset($this->_tagged[$id])) { + $extension = $this->_tagged[$id]['extension']; + } else { + $extension = $this->_options['file_extension']; + } + $file = $pathName . '/' . $fileName . $extension; + if (file_exists($file)) { + return true; + } + return false; + } + + /** + * Save some string datas into a cache record + * + * Note : $data is always "string" (serialization is done by the + * core not by the backend) + * + * @param string $data Datas to cache + * @param string $id Cache id + * @param array $tags Array of strings, the cache record will be tagged by each string entry + * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) + * @return boolean true if no problem + */ + public function save($data, $id, $tags = array(), $specificLifetime = false) + { + if ($this->_options['disable_caching']) { + return true; + } + $extension = null; + if ($this->_isSerialized($data)) { + $data = unserialize($data); + $extension = '.' . ltrim($data[1], '.'); + $data = $data[0]; + } + + clearstatcache(); + if (is_null($id) || strlen($id) == 0) { + $id = $this->_detectId(); + } else { + $id = $this->_decodeId($id); + } + + $fileName = basename($id); + if (empty($fileName)) { + $fileName = $this->_options['index_filename']; + } + + $pathName = realpath($this->_options['public_dir']) . dirname($id); + $this->_createDirectoriesFor($pathName); + + if (is_null($id) || strlen($id) == 0) { + $dataUnserialized = unserialize($data); + $data = $dataUnserialized['data']; + } + $ext = $this->_options['file_extension']; + if ($extension) $ext = $extension; + $file = rtrim($pathName, '/') . '/' . $fileName . $ext; + if ($this->_options['file_locking']) { + $result = file_put_contents($file, $data, LOCK_EX); + } else { + $result = file_put_contents($file, $data); + } + @chmod($file, $this->_octdec($this->_options['cache_file_umask'])); + + if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { + $this->_tagged = $tagged; + } elseif (is_null($this->_tagged)) { + $this->_tagged = array(); + } + if (!isset($this->_tagged[$id])) { + $this->_tagged[$id] = array(); + } + if (!isset($this->_tagged[$id]['tags'])) { + $this->_tagged[$id]['tags'] = array(); + } + $this->_tagged[$id]['tags'] = array_unique(array_merge($this->_tagged[$id]['tags'], $tags)); + $this->_tagged[$id]['extension'] = $ext; + $this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME); + return (bool) $result; + } + + /** + * Recursively create the directories needed to write the static file + */ + protected function _createDirectoriesFor($path) + { + $parts = explode('/', $path); + $directory = ''; + foreach ($parts as $part) { + $directory = rtrim($directory, '/') . '/' . $part; + if (!is_dir($directory)) { + mkdir($directory, $this->_octdec($this->_options['cache_directory_umask'])); + } + } + } + + /** + * Detect serialization of data (cannot predict since this is the only way + * to obey the interface yet pass in another parameter). + * + * In future, ZF 2.0, check if we can just avoid the interface restraints. + * + * This format is the only valid one possible for the class, so it's simple + * to just run a regular expression for the starting serialized format. + */ + protected function _isSerialized($data) + { + return preg_match("/a:2:\{i:0;s:\d+:\"/", $data); + } + + /** + * Remove a cache record + * + * @param string $id Cache id + * @return boolean True if no problem + */ + public function remove($id) + { + if (!$this->_verifyPath($id)) { + Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path'); + } + $fileName = basename($id); + if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { + $this->_tagged = $tagged; + } elseif (!$this->_tagged) { + return false; + } + if (isset($this->_tagged[$id])) { + $extension = $this->_tagged[$id]['extension']; + } else { + $extension = $this->_options['file_extension']; + } + if (empty($fileName)) { + $fileName = $this->_options['index_filename']; + } + $pathName = $this->_options['public_dir'] . dirname($id); + $file = realpath($pathName) . '/' . $fileName . $extension; + if (!file_exists($file)) { + return false; + } + return unlink($file); + } + + /** + * Remove a cache record recursively for the given directory matching a + * REQUEST_URI based relative path (deletes the actual file matching this + * in addition to the matching directory) + * + * @param string $id Cache id + * @return boolean True if no problem + */ + public function removeRecursively($id) + { + if (!$this->_verifyPath($id)) { + Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path'); + } + $fileName = basename($id); + if (empty($fileName)) { + $fileName = $this->_options['index_filename']; + } + $pathName = $this->_options['public_dir'] . dirname($id); + $file = $pathName . '/' . $fileName . $this->_options['file_extension']; + $directory = $pathName . '/' . $fileName; + if (file_exists($directory)) { + if (!is_writable($directory)) { + return false; + } + foreach (new DirectoryIterator($directory) as $file) { + if (true === $file->isFile()) { + if (false === unlink($file->getPathName())) { + return false; + } + } + } + rmdir(dirname($path)); + } + if (file_exists($file)) { + if (!is_writable($file)) { + return false; + } + return unlink($file); + } + return true; + } + + /** + * Clean some cache records + * + * Available modes are : + * Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) + * Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) + * Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags + * ($tags can be an array of strings or a single string) + * Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags} + * ($tags can be an array of strings or a single string) + * Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags + * ($tags can be an array of strings or a single string) + * + * @param string $mode Clean mode + * @param array $tags Array of tags + * @return boolean true if no problem + */ + public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) + { + $result = false; + switch ($mode) { + case Zend_Cache::CLEANING_MODE_MATCHING_TAG: + case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: + if (empty($tags)) { + throw new Zend_Exception('Cannot use tag matching modes as no tags were defined'); + } + if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) { + $this->_tagged = $tagged; + } elseif (!$this->_tagged) { + return true; + } + foreach ($tags as $tag) { + $urls = array_keys($this->_tagged); + foreach ($urls as $url) { + if (isset($this->_tagged[$url]['tags']) && in_array($tag, $this->_tagged[$url]['tags'])) { + $this->remove($url); + unset($this->_tagged[$url]); + } + } + } + $this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME); + $result = true; + break; + case Zend_Cache::CLEANING_MODE_ALL: + if (is_null($this->_tagged)) { + $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME); + $this->_tagged = $tagged; + } + if (is_null($this->_tagged) || empty($this->_tagged)) { + return true; + } + $urls = array_keys($this->_tagged); + foreach ($urls as $url) { + $this->remove($url); + unset($this->_tagged[$url]); + } + $this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME); + $result = true; + break; + case Zend_Cache::CLEANING_MODE_OLD: + $this->_log("Zend_Cache_Backend_Static : Selected Cleaning Mode Currently Unsupported By This Backend"); + break; + case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: + if (empty($tags)) { + throw new Zend_Exception('Cannot use tag matching modes as no tags were defined'); + } + if (is_null($this->_tagged)) { + $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME); + $this->_tagged = $tagged; + } + if (is_null($this->_tagged) || empty($this->_tagged)) { + return true; + } + $urls = array_keys($this->_tagged); + foreach ($urls as $url) { + $difference = array_diff($tags, $this->_tagged[$url]['tags']); + if (count($tags) == count($difference)) { + $this->remove($url); + unset($this->_tagged[$url]); + } + } + $this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME); + $result = true; + break; + default: + Zend_Cache::throwException('Invalid mode for clean() method'); + break; + } + return $result; + } + + /** + * Set an Inner Cache, used here primarily to store Tags associated + * with caches created by this backend. Note: If Tags are lost, the cache + * should be completely cleaned as the mapping of tags to caches will + * have been irrevocably lost. + * + * @param Zend_Cache_Core + * @return void + */ + public function setInnerCache(Zend_Cache_Core $cache) + { + $this->_tagCache = $cache; + $this->_options['tag_cache'] = $cache; + } + + /** + * Get the Inner Cache if set + * + * @return Zend_Cache_Core + */ + public function getInnerCache() + { + if (is_null($this->_tagCache)) { + Zend_Cache::throwException('An Inner Cache has not been set; use setInnerCache()'); + } + return $this->_tagCache; + } + + /** + * Verify path exists and is non-empty + * + * @param string $path + * @return bool + */ + protected function _verifyPath($path) + { + $path = realpath($path); + $base = realpath($this->_options['public_dir']); + return strncmp($path, $base, strlen($base)) !== 0; + } + + /** + * Determine the page to save from the request + * + * @return string + */ + protected function _detectId() + { + return $_SERVER['REQUEST_URI']; + } + + /** + * Validate a cache id or a tag (security, reliable filenames, reserved prefixes...) + * + * Throw an exception if a problem is found + * + * @param string $string Cache id or tag + * @throws Zend_Cache_Exception + * @return void + * @deprecated Not usable until perhaps ZF 2.0 + */ + protected static function _validateIdOrTag($string) + { + if (!is_string($string)) { + Zend_Cache::throwException('Invalid id or tag : must be a string'); + } + + // Internal only checked in Frontend - not here! + if (substr($string, 0, 9) == 'internal-') { + return; + } + + // Validation assumes no query string, fragments or scheme included - only the path + if (!preg_match( + '/^(?:\/(?:(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*\'()\[\]:@&=+$,;])*)?)+$/', + $string + ) + ) { + Zend_Cache::throwException("Invalid id or tag '$string' : must be a valid URL path"); + } + } + + /** + * Detect an octal string and return its octal value for file permission ops + * otherwise return the non-string (assumed octal or decimal int already) + * + * @param $val The potential octal in need of conversion + * @return int + */ + protected function _octdec($val) + { + if (decoct(octdec($val)) == $val && is_string($val)) { + return octdec($val); + } + return $val; + } + + /** + * Decode a request URI from the provided ID + */ + protected function _decodeId($id) + { + return pack('H*', $id);; + } +} diff --git a/libs/Zend/Cache/Backend/Test.php b/libs/Zend/Cache/Backend/Test.php index 713b48954a..f143ab4609 100644 --- a/libs/Zend/Cache/Backend/Test.php +++ b/libs/Zend/Cache/Backend/Test.php @@ -15,29 +15,29 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: Test.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Test.php 21292 2010-03-02 10:25:22Z mabe $ */ /** * @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend/Interface.php'; +// require_once 'Zend/Cache/Backend/ExtendedInterface.php'; /** * @see Zend_Cache_Backend */ -require_once 'Zend/Cache/Backend.php'; +// require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface +class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface { /** * Available options @@ -103,7 +103,11 @@ class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_B public function load($id, $doNotTestCacheValidity = false) { $this->_addLog('get', array($id, $doNotTestCacheValidity)); - if ($id=='false') { + if ( $id == 'false' + || $id == 'd8523b3ee441006261eeffa5c3d3a0a7' + || $id == 'e83249ea22178277d5befc2c5e2e9ace' + || $id == '40f649b94977c0a6e76902e2a0b43587') + { return false; } if ($id=='serialized') { @@ -136,10 +140,7 @@ class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_B if ($id=='false') { return false; } - if (($id=='d8523b3ee441006261eeffa5c3d3a0a7') or ($id=='3c439c922209e2cb0b54d6deffccd75a')) { - return false; - } - if (($id=='40f649b94977c0a6e76902e2a0b43587') or ($id=='e83249ea22178277d5befc2c5e2e9ace')) { + if (($id=='3c439c922209e2cb0b54d6deffccd75a')) { return false; } return 123456; @@ -252,6 +253,145 @@ class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_B } /** + * Return an array of stored cache ids + * + * @return array array of stored cache ids (string) + */ + public function getIds() + { + return array( + 'prefix_id1', 'prefix_id2' + ); + } + + /** + * Return an array of stored tags + * + * @return array array of stored tags (string) + */ + public function getTags() + { + return array( + 'tag1', 'tag2' + ); + } + + /** + * Return an array of stored cache ids which match given tags + * + * In case of multiple tags, a logical AND is made between tags + * + * @param array $tags array of tags + * @return array array of matching cache ids (string) + */ + public function getIdsMatchingTags($tags = array()) + { + if ($tags == array('tag1', 'tag2')) { + return array('prefix_id1', 'prefix_id2'); + } + + return array(); + } + + /** + * Return an array of stored cache ids which don't match given tags + * + * In case of multiple tags, a logical OR is made between tags + * + * @param array $tags array of tags + * @return array array of not matching cache ids (string) + */ + public function getIdsNotMatchingTags($tags = array()) + { + if ($tags == array('tag3', 'tag4')) { + return array('prefix_id3', 'prefix_id4'); + } + + return array(); + } + + /** + * Return an array of stored cache ids which match any given tags + * + * In case of multiple tags, a logical AND is made between tags + * + * @param array $tags array of tags + * @return array array of any matching cache ids (string) + */ + public function getIdsMatchingAnyTags($tags = array()) + { + if ($tags == array('tag5', 'tag6')) { + return array('prefix_id5', 'prefix_id6'); + } + + return array(); + } + + /** + * Return the filling percentage of the backend storage + * + * @return int integer between 0 and 100 + */ + public function getFillingPercentage() + { + return 50; + } + + /** + * Return an array of metadatas for the given cache id + * + * The array must include these keys : + * - expire : the expire timestamp + * - tags : a string array of tags + * - mtime : timestamp of last modification time + * + * @param string $id cache id + * @return array array of metadatas (false if the cache id is not found) + */ + public function getMetadatas($id) + { + return false; + } + + /** + * Give (if possible) an extra lifetime to the given cache id + * + * @param string $id cache id + * @param int $extraLifetime + * @return boolean true if ok + */ + public function touch($id, $extraLifetime) + { + return true; + } + + /** + * Return an associative array of capabilities (booleans) of the backend + * + * The array must include these keys : + * - automatic_cleaning (is automating cleaning necessary) + * - tags (are tags supported) + * - expired_read (is it possible to read expired cache records + * (for doNotTestCacheValidity option for example)) + * - priority does the backend deal with priority when saving + * - infinite_lifetime (is infinite lifetime can work with this backend) + * - get_list (is it possible to get the list of cache ids and the complete list of tags) + * + * @return array associative of with capabilities + */ + public function getCapabilities() + { + return array( + 'automatic_cleaning' => true, + 'tags' => true, + 'expired_read' => false, + 'priority' => true, + 'infinite_lifetime' => true, + 'get_list' => true + ); + } + + /** * Add an event to the log array * * @param string $methodName MethodName diff --git a/libs/Zend/Cache/Backend/TwoLevels.php b/libs/Zend/Cache/Backend/TwoLevels.php index b340645f6c..a537b739ca 100644 --- a/libs/Zend/Cache/Backend/TwoLevels.php +++ b/libs/Zend/Cache/Backend/TwoLevels.php @@ -15,27 +15,27 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: TwoLevels.php 17741 2009-08-22 02:58:33Z yoshida@zend.co.jp $ + * @version $Id: TwoLevels.php 21954 2010-04-19 19:19:24Z mabe $ */ /** * @see Zend_Cache_Backend_ExtendedInterface */ -require_once 'Zend/Cache/Backend/ExtendedInterface.php'; +// require_once 'Zend/Cache/Backend/ExtendedInterface.php'; /** * @see Zend_Cache_Backend */ -require_once 'Zend/Cache/Backend.php'; +// require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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 */ @@ -95,21 +95,21 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca * * @var Zend_Cache_Backend */ - private $_slowBackend; + protected $_slowBackend; /** * Fast Backend * * @var Zend_Cache_Backend */ - private $_fastBackend; + protected $_fastBackend; /** * Cache for the fast backend filling percentage * * @var int */ - private $_fastBackendFillingPercentage = null; + protected $_fastBackendFillingPercentage = null; /** * Constructor @@ -121,20 +121,39 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca public function __construct(array $options = array()) { parent::__construct($options); + if ($this->_options['slow_backend'] === null) { Zend_Cache::throwException('slow_backend option has to set'); + } elseif ($this->_options['slow_backend'] instanceof Zend_Cache_Backend_ExtendedInterface) { + $this->_slowBackend = $this->_options['slow_backend']; + } else { + $this->_slowBackend = Zend_Cache::_makeBackend( + $this->_options['slow_backend'], + $this->_options['slow_backend_options'], + $this->_options['slow_backend_custom_naming'], + $this->_options['slow_backend_autoload'] + ); + if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_slowBackend))) { + Zend_Cache::throwException('slow_backend must implement the Zend_Cache_Backend_ExtendedInterface interface'); + } } + if ($this->_options['fast_backend'] === null) { Zend_Cache::throwException('fast_backend option has to set'); + } elseif ($this->_options['fast_backend'] instanceof Zend_Cache_Backend_ExtendedInterface) { + $this->_fastBackend = $this->_options['fast_backend']; + } else { + $this->_fastBackend = Zend_Cache::_makeBackend( + $this->_options['fast_backend'], + $this->_options['fast_backend_options'], + $this->_options['fast_backend_custom_naming'], + $this->_options['fast_backend_autoload'] + ); + if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_fastBackend))) { + Zend_Cache::throwException('fast_backend must implement the Zend_Cache_Backend_ExtendedInterface interface'); + } } - $this->_slowBackend = Zend_Cache::_makeBackend($this->_options['slow_backend'], $this->_options['slow_backend_options'], $this->_options['slow_backend_custom_naming'], $this->_options['slow_backend_autoload']); - $this->_fastBackend = Zend_Cache::_makeBackend($this->_options['fast_backend'], $this->_options['fast_backend_options'], $this->_options['fast_backend_custom_naming'], $this->_options['fast_backend_autoload']); - if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_slowBackend))) { - Zend_Cache::throwException('slow_backend must implement the Zend_Cache_Backend_ExtendedInterface interface'); - } - if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_fastBackend))) { - Zend_Cache::throwException('fast_backend must implement the Zend_Cache_Backend_ExtendedInterface interface'); - } + $this->_slowBackend->setDirectives($this->_directives); $this->_fastBackend->setDirectives($this->_directives); } @@ -177,8 +196,14 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca if (($priority > 0) && (10 * $priority >= $usage)) { $fastLifetime = $this->_getFastLifetime($lifetime, $priority); $boolFast = $this->_fastBackend->save($preparedData, $id, array(), $fastLifetime); + $boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime); + } else { + $boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime); + if ($boolSlow === true) { + $boolFast = $this->_fastBackend->remove($id); + } } - $boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime); + return ($boolFast && $boolSlow); } diff --git a/libs/Zend/Cache/Backend/Xcache.php b/libs/Zend/Cache/Backend/Xcache.php index 8f7af5963f..ccd9672ca6 100644 --- a/libs/Zend/Cache/Backend/Xcache.php +++ b/libs/Zend/Cache/Backend/Xcache.php @@ -15,27 +15,27 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: Xcache.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Xcache.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend/Interface.php'; +// require_once 'Zend/Cache/Backend/Interface.php'; /** * @see Zend_Cache_Backend */ -require_once 'Zend/Cache/Backend.php'; +// require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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_Backend_Xcache extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface @@ -46,7 +46,7 @@ class Zend_Cache_Backend_Xcache extends Zend_Cache_Backend implements Zend_Cache */ const TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::clean() : tags are unsupported by the Xcache backend'; const TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::save() : tags are unsupported by the Xcache backend'; - + /** * Available options * diff --git a/libs/Zend/Cache/Backend/ZendPlatform.php b/libs/Zend/Cache/Backend/ZendPlatform.php index 71bbdab3e0..90b7c608c4 100644 --- a/libs/Zend/Cache/Backend/ZendPlatform.php +++ b/libs/Zend/Cache/Backend/ZendPlatform.php @@ -15,20 +15,20 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: ZendPlatform.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: ZendPlatform.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend.php'; +// require_once 'Zend/Cache/Backend.php'; /** * @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend/Interface.php'; +// require_once 'Zend/Cache/Backend/Interface.php'; /** @@ -36,7 +36,7 @@ require_once 'Zend/Cache/Backend/Interface.php'; * * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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_Backend_ZendPlatform extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface diff --git a/libs/Zend/Cache/Backend/ZendServer.php b/libs/Zend/Cache/Backend/ZendServer.php index 55840efa43..f7a62f6276 100644 --- a/libs/Zend/Cache/Backend/ZendServer.php +++ b/libs/Zend/Cache/Backend/ZendServer.php @@ -15,23 +15,23 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: ZendServer.php 17672 2009-08-19 13:05:18Z yoshida@zend.co.jp $ + * @version $Id: ZendServer.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend/Interface.php'; +// require_once 'Zend/Cache/Backend/Interface.php'; /** @see Zend_Cache_Backend */ -require_once 'Zend/Cache/Backend.php'; +// require_once 'Zend/Cache/Backend.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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 */ abstract class Zend_Cache_Backend_ZendServer extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface diff --git a/libs/Zend/Cache/Backend/ZendServer/Disk.php b/libs/Zend/Cache/Backend/ZendServer/Disk.php index ba0dd4b366..49c604d005 100644 --- a/libs/Zend/Cache/Backend/ZendServer/Disk.php +++ b/libs/Zend/Cache/Backend/ZendServer/Disk.php @@ -15,23 +15,23 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: Disk.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Disk.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend/Interface.php'; +// require_once 'Zend/Cache/Backend/Interface.php'; /** @see Zend_Cache_Backend_ZendServer */ -require_once 'Zend/Cache/Backend/ZendServer.php'; +// require_once 'Zend/Cache/Backend/ZendServer.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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_Backend_ZendServer_Disk extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface @@ -50,7 +50,7 @@ class Zend_Cache_Backend_ZendServer_Disk extends Zend_Cache_Backend_ZendServer i parent::__construct($options); } - /** + /** * Store data * * @param mixed $data Object to store @@ -60,13 +60,13 @@ class Zend_Cache_Backend_ZendServer_Disk extends Zend_Cache_Backend_ZendServer i */ protected function _store($data, $id, $timeToLive) { - if (zend_disk_cache_store($this->_options['namespace'] . '::' . $id, - $data, - $timeToLive) === false) { + if (zend_disk_cache_store($this->_options['namespace'] . '::' . $id, + $data, + $timeToLive) === false) { $this->_log('Store operation failed.'); return false; - } - return true; + } + return true; } /** @@ -76,7 +76,7 @@ class Zend_Cache_Backend_ZendServer_Disk extends Zend_Cache_Backend_ZendServer i */ protected function _fetch($id) { - return zend_disk_cache_fetch($this->_options['namespace'] . '::' . $id); + return zend_disk_cache_fetch($this->_options['namespace'] . '::' . $id); } /** @@ -87,7 +87,7 @@ class Zend_Cache_Backend_ZendServer_Disk extends Zend_Cache_Backend_ZendServer i */ protected function _unset($id) { - return zend_disk_cache_delete($this->_options['namespace'] . '::' . $id); + return zend_disk_cache_delete($this->_options['namespace'] . '::' . $id); } /** @@ -95,6 +95,6 @@ class Zend_Cache_Backend_ZendServer_Disk extends Zend_Cache_Backend_ZendServer i */ protected function _clear() { - zend_disk_cache_clear($this->_options['namespace']); + zend_disk_cache_clear($this->_options['namespace']); } } diff --git a/libs/Zend/Cache/Backend/ZendServer/ShMem.php b/libs/Zend/Cache/Backend/ZendServer/ShMem.php index 8e42eb60f1..fd08df68bb 100644 --- a/libs/Zend/Cache/Backend/ZendServer/ShMem.php +++ b/libs/Zend/Cache/Backend/ZendServer/ShMem.php @@ -15,23 +15,23 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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: ShMem.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: ShMem.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** @see Zend_Cache_Backend_Interface */ -require_once 'Zend/Cache/Backend/Interface.php'; +// require_once 'Zend/Cache/Backend/Interface.php'; /** @see Zend_Cache_Backend_ZendServer */ -require_once 'Zend/Cache/Backend/ZendServer.php'; +// require_once 'Zend/Cache/Backend/ZendServer.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Backend - * @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_Backend_ZendServer_ShMem extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface 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; } diff --git a/libs/Zend/Cache/Exception.php b/libs/Zend/Cache/Exception.php index 1e1e62c4d8..63a4a28838 100644 --- a/libs/Zend/Cache/Exception.php +++ b/libs/Zend/Cache/Exception.php @@ -14,19 +14,19 @@ * * @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: Exception.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Exception */ -require_once 'Zend/Exception.php'; +// require_once 'Zend/Exception.php'; /** * @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_Exception extends Zend_Exception {} diff --git a/libs/Zend/Cache/Frontend/Capture.php b/libs/Zend/Cache/Frontend/Capture.php new file mode 100644 index 0000000000..8536c5ffb5 --- /dev/null +++ b/libs/Zend/Cache/Frontend/Capture.php @@ -0,0 +1,87 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Cache + * @subpackage Zend_Cache_Frontend + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + + +/** + * @see Zend_Cache_Core + */ +// require_once 'Zend/Cache/Core.php'; + + +/** + * @package Zend_Cache + * @subpackage Zend_Cache_Frontend + * @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_Frontend_Capture extends Zend_Cache_Core +{ + /** + * Page identifiers + * @var array + */ + protected $_idStack = array(); + + /** + * Tags + * @var array + */ + protected $_tags = array(); + + protected $_extension = null; + + /** + * Start the cache + * + * @param string $id Cache id + * @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas) + */ + public function start($id, array $tags, $extension = null) + { + $this->_tags = $tags; + $this->_extension = $extension; + ob_start(array($this, '_flush')); + ob_implicit_flush(false); + $this->_idStack[] = $id; + return false; + } + + /** + * callback for output buffering + * (shouldn't really be called manually) + * + * @param string $data Buffered output + * @return string Data to send to browser + */ + public function _flush($data) + { + $id = array_pop($this->_idStack); + if (is_null($id)) { + Zend_Cache::throwException('use of _flush() without a start()'); + } + if ($this->_extension) { + $this->save(serialize(array($data, $this->_extension)), $id, $this->_tags); + } else { + $this->save($data, $id, $this->_tags); + } + return $data; + } +} diff --git a/libs/Zend/Cache/Frontend/Class.php b/libs/Zend/Cache/Frontend/Class.php index 6c4ef471b8..3dbdcf666b 100644 --- a/libs/Zend/Cache/Frontend/Class.php +++ b/libs/Zend/Cache/Frontend/Class.php @@ -15,21 +15,21 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @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: Class.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Class.php 20379 2010-01-18 14:40:57Z mabe $ */ /** * @see Zend_Cache_Core */ -require_once 'Zend/Cache/Core.php'; +// require_once 'Zend/Cache/Core.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @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_Frontend_Class extends Zend_Cache_Core @@ -208,14 +208,14 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core // We do not have not cache return call_user_func_array(array($this->_cachedEntity, $name), $parameters); } + $id = $this->_makeId($name, $parameters); - if ($this->test($id)) { + if ( ($rs = $this->load($id)) && isset($rs[0], $rs[1]) ) { // A cache is available - $result = $this->load($id); - $output = $result[0]; - $return = $result[1]; + $output = $rs[0]; + $return = $rs[1]; } else { - // A cache is not available + // A cache is not available (or not valid for this frontend) ob_start(); ob_implicit_flush(false); $return = call_user_func_array(array($this->_cachedEntity, $name), $parameters); @@ -224,6 +224,7 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core $data = array($output, $return); $this->save($data, $id, $this->_tags, $this->_specificLifetime, $this->_priority); } + echo $output; return $return; } diff --git a/libs/Zend/Cache/Frontend/File.php b/libs/Zend/Cache/Frontend/File.php index 5e28e015d5..2cbfe74d0c 100644 --- a/libs/Zend/Cache/Frontend/File.php +++ b/libs/Zend/Cache/Frontend/File.php @@ -15,66 +15,66 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @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: File.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Cache_Core */ -require_once 'Zend/Cache/Core.php'; +// require_once 'Zend/Cache/Core.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @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_Frontend_File extends Zend_Cache_Core { - - /** - * Consts for master_files_mode - */ - const MODE_AND = 'AND'; - const MODE_OR = 'OR'; - + + /** + * Consts for master_files_mode + */ + const MODE_AND = 'AND'; + const MODE_OR = 'OR'; + /** * Available options * * ====> (string) master_file : * - a complete path of the master file * - deprecated (see master_files) - * + * * ====> (array) master_files : * - an array of complete path of master files * - this option has to be set ! - * + * * ====> (string) master_files_mode : * - Zend_Cache_Frontend_File::MODE_AND or Zend_Cache_Frontend_File::MODE_OR * - if MODE_AND, then all master files have to be touched to get a cache invalidation * - if MODE_OR (default), then a single touched master file is enough to get a cache invalidation * * ====> (boolean) ignore_missing_master_files - * - if set to true, missing master files are ignored silently + * - if set to true, missing master files are ignored silently * - if set to false (default), an exception is thrown if there is a missing master file * @var array available options */ protected $_specificOptions = array( - 'master_file' => null, + 'master_file' => null, 'master_files' => null, - 'master_files_mode' => 'OR', - 'ignore_missing_master_files' => false + 'master_files_mode' => 'OR', + 'ignore_missing_master_files' => false ); /** * Master file mtimes * * Array of int - * + * * @var array */ private $_masterFile_mtimes = null; @@ -95,10 +95,10 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core Zend_Cache::throwException('master_files option must be set'); } } - + /** * Change the master_file option - * + * * @param string $masterFile the complete path and name of the master file */ public function setMasterFiles($masterFiles) @@ -109,27 +109,27 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core $this->_masterFile_mtimes = array(); $i = 0; foreach ($masterFiles as $masterFile) { - $this->_masterFile_mtimes[$i] = @filemtime($masterFile); - if ((!($this->_specificOptions['ignore_missing_master_files'])) && (!($this->_masterFile_mtimes[$i]))) { - Zend_Cache::throwException('Unable to read master_file : '.$masterFile); - } - $i++; + $this->_masterFile_mtimes[$i] = @filemtime($masterFile); + if ((!($this->_specificOptions['ignore_missing_master_files'])) && (!($this->_masterFile_mtimes[$i]))) { + Zend_Cache::throwException('Unable to read master_file : '.$masterFile); + } + $i++; } } - + /** * Change the master_file option - * - * To keep the compatibility - * + * + * To keep the compatibility + * * @deprecated * @param string $masterFile the complete path and name of the master file - */ + */ public function setMasterFile($masterFile) { - $this->setMasterFiles(array(0 => $masterFile)); + $this->setMasterFiles(array(0 => $masterFile)); } - + /** * Public frontend to set an option * @@ -145,7 +145,7 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core if ($name == 'master_file') { $this->setMasterFile($value); } else if ($name == 'master_files') { - $this->setMasterFiles($value); + $this->setMasterFiles($value); } else { parent::setOption($name, $value); } @@ -174,33 +174,33 @@ class Zend_Cache_Frontend_File extends 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) { $lastModified = parent::test($id); if ($lastModified) { - if ($this->_specificOptions['master_files_mode'] == self::MODE_AND) { - // MODE_AND - foreach($this->_masterFile_mtimes as $masterFileMTime) { - if ($masterFileMTime) { - if ($lastModified > $masterFileMTime) { - return $lastModified; - } - } - } - } else { - // MODE_OR - $res = true; - foreach($this->_masterFile_mtimes as $masterFileMTime) { - if ($masterFileMTime) { - if ($lastModified <= $masterFileMTime) { - return false; - } - } - } - return $lastModified; - } + if ($this->_specificOptions['master_files_mode'] == self::MODE_AND) { + // MODE_AND + foreach($this->_masterFile_mtimes as $masterFileMTime) { + if ($masterFileMTime) { + if ($lastModified > $masterFileMTime) { + return $lastModified; + } + } + } + } else { + // MODE_OR + $res = true; + foreach($this->_masterFile_mtimes as $masterFileMTime) { + if ($masterFileMTime) { + if ($lastModified <= $masterFileMTime) { + return false; + } + } + } + return $lastModified; + } } return false; } diff --git a/libs/Zend/Cache/Frontend/Function.php b/libs/Zend/Cache/Frontend/Function.php index 03e28931ce..7d7f827fee 100644 --- a/libs/Zend/Cache/Frontend/Function.php +++ b/libs/Zend/Cache/Frontend/Function.php @@ -15,22 +15,22 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @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: Function.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Function.php 20379 2010-01-18 14:40:57Z mabe $ */ /** * @see Zend_Cache_Core */ -require_once 'Zend/Cache/Core.php'; +// require_once 'Zend/Cache/Core.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @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_Frontend_Function extends Zend_Cache_Core @@ -76,7 +76,7 @@ class Zend_Cache_Frontend_Function extends Zend_Cache_Core * @param array $parameters Function parameters * @param array $tags Cache tags * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) - * @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends + * @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends * @return mixed Result */ public function call($name, $parameters = array(), $tags = array(), $specificLifetime = false, $priority = 8) @@ -89,14 +89,14 @@ class Zend_Cache_Frontend_Function extends Zend_Cache_Core // We do not have not cache return call_user_func_array($name, $parameters); } + $id = $this->_makeId($name, $parameters); - if ($this->test($id)) { + if ( ($rs = $this->load($id)) && isset($rs[0], $rs[1])) { // A cache is available - $result = $this->load($id); - $output = $result[0]; - $return = $result[1]; + $output = $rs[0]; + $return = $rs[1]; } else { - // A cache is not available + // A cache is not available (or not valid for this frontend) ob_start(); ob_implicit_flush(false); $return = call_user_func_array($name, $parameters); @@ -105,6 +105,7 @@ class Zend_Cache_Frontend_Function extends Zend_Cache_Core $data = array($output, $return); $this->save($data, $id, $tags, $specificLifetime, $priority); } + echo $output; return $return; } diff --git a/libs/Zend/Cache/Frontend/Output.php b/libs/Zend/Cache/Frontend/Output.php index 00f200d722..1757381ce4 100644 --- a/libs/Zend/Cache/Frontend/Output.php +++ b/libs/Zend/Cache/Frontend/Output.php @@ -15,22 +15,22 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @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: Output.php 16541 2009-07-07 06:59:03Z bkarwin $ + * @version $Id: Output.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Cache_Core */ -require_once 'Zend/Cache/Core.php'; +// require_once 'Zend/Cache/Core.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @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_Frontend_Output extends Zend_Cache_Core diff --git a/libs/Zend/Cache/Frontend/Page.php b/libs/Zend/Cache/Frontend/Page.php index 8a6a6f64f4..21ce6537a7 100644 --- a/libs/Zend/Cache/Frontend/Page.php +++ b/libs/Zend/Cache/Frontend/Page.php @@ -15,22 +15,22 @@ * @category Zend * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @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: Page.php 16974 2009-07-22 19:23:08Z matthew $ + * @version $Id: Page.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** * @see Zend_Cache_Core */ -require_once 'Zend/Cache/Core.php'; +// require_once 'Zend/Cache/Core.php'; /** * @package Zend_Cache * @subpackage Zend_Cache_Frontend - * @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_Frontend_Page extends Zend_Cache_Core @@ -275,7 +275,7 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core header("$name: $value"); } } - if ($this->_specificOptions['debug_header']) { + if ($this->_specificOptions['debug_header']) { echo 'DEBUG HEADER : This is a cached page !'; } echo $data; @@ -339,9 +339,9 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core { $tmp = $_SERVER['REQUEST_URI']; $array = explode('?', $tmp, 2); - $tmp = $array[0]; + $tmp = $array[0]; foreach (array('Get', 'Post', 'Session', 'Files', 'Cookie') as $arrayName) { - $tmp2 = $this->_makePartialId($arrayName, $this->_activeOptions['cache_with_' . strtolower($arrayName) . '_variables'], $this->_activeOptions['make_id_with_' . strtolower($arrayName) . '_variables']); + $tmp2 = $this->_makePartialId($arrayName, $this->_activeOptions['cache_with_' . strtolower($arrayName) . '_variables'], $this->_activeOptions['make_id_with_' . strtolower($arrayName) . '_variables']); if ($tmp2===false) { return false; } @@ -360,7 +360,7 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core */ protected function _makePartialId($arrayName, $bool1, $bool2) { - switch ($arrayName) { + switch ($arrayName) { case 'Get': $var = $_GET; break; diff --git a/libs/Zend/Cache/Manager.php b/libs/Zend/Cache/Manager.php new file mode 100644 index 0000000000..d7f157038c --- /dev/null +++ b/libs/Zend/Cache/Manager.php @@ -0,0 +1,286 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Cache + * @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$ + */ + +/** @see Zend_Cache_Exception */ +// require_once 'Zend/Cache/Exception.php'; + +/** @see Zend_Cache */ +// require_once 'Zend/Cache.php'; + +/** + * @category Zend + * @package Zend_Cache + * @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_Manager +{ + /** + * Constant holding reserved name for default Page Cache + */ + const PAGECACHE = 'page'; + + /** + * Constant holding reserved name for default Page Tag Cache + */ + const PAGETAGCACHE = 'pagetag'; + + /** + * Array of caches stored by the Cache Manager instance + * + * @var array + */ + protected $_caches = array(); + + /** + * Array of ready made configuration templates for lazy + * loading caches. + * + * @var array + */ + protected $_optionTemplates = array( + // Null Cache (Enforce Null/Empty Values) + 'skeleton' => array( + 'frontend' => array( + 'name' => null, + 'options' => array(), + ), + 'backend' => array( + 'name' => null, + 'options' => array(), + ), + ), + // Simple Common Default + 'default' => array( + 'frontend' => array( + 'name' => 'Core', + 'options' => array( + 'automatic_serialization' => true, + ), + ), + 'backend' => array( + 'name' => 'File', + 'options' => array( + 'cache_dir' => '../cache', + ), + ), + ), + // Static Page HTML Cache + 'page' => array( + 'frontend' => array( + 'name' => 'Capture', + 'options' => array( + 'ignore_user_abort' => true, + ), + ), + 'backend' => array( + 'name' => 'Static', + 'options' => array( + 'public_dir' => '../public', + ), + ), + ), + // Tag Cache + 'pagetag' => array( + 'frontend' => array( + 'name' => 'Core', + 'options' => array( + 'automatic_serialization' => true, + 'lifetime' => null + ), + ), + 'backend' => array( + 'name' => 'File', + 'options' => array( + 'cache_dir' => '../cache', + 'cache_file_umask' => 0644 + ), + ), + ), + ); + + /** + * Set a new cache for the Cache Manager to contain + * + * @param string $name + * @param Zend_Cache_Core $cache + * @return Zend_Cache_Manager + */ + public function setCache($name, Zend_Cache_Core $cache) + { + $this->_caches[$name] = $cache; + return $this; + } + + /** + * Check if the Cache Manager contains the named cache object, or a named + * configuration template to lazy load the cache object + * + * @param string $name + * @return bool + */ + public function hasCache($name) + { + if (isset($this->_caches[$name]) + || $this->hasCacheTemplate($name) + ) { + return true; + } + return false; + } + + /** + * Fetch the named cache object, or instantiate and return a cache object + * using a named configuration template + * + * @param string $name + * @return Zend_Cache_Core + */ + public function getCache($name) + { + if (isset($this->_caches[$name])) { + return $this->_caches[$name]; + } + if (isset($this->_optionTemplates[$name])) { + if ($name == self::PAGECACHE + && (!isset($this->_optionTemplates[$name]['backend']['options']['tag_cache']) + || !$this->_optionTemplates[$name]['backend']['options']['tag_cache'] instanceof Zend_Cache_Core) + ) { + $this->_optionTemplates[$name]['backend']['options']['tag_cache'] + = $this->getCache(self::PAGETAGCACHE); + } + $this->_caches[$name] = Zend_Cache::factory( + $this->_optionTemplates[$name]['frontend']['name'], + $this->_optionTemplates[$name]['backend']['name'], + isset($this->_optionTemplates[$name]['frontend']['options']) ? $this->_optionTemplates[$name]['frontend']['options'] : array(), + isset($this->_optionTemplates[$name]['backend']['options']) ? $this->_optionTemplates[$name]['backend']['options'] : array(), + isset($this->_optionTemplates[$name]['frontend']['customFrontendNaming']) ? $this->_optionTemplates[$name]['frontend']['customFrontendNaming'] : false, + isset($this->_optionTemplates[$name]['backend']['customBackendNaming']) ? $this->_optionTemplates[$name]['backend']['customBackendNaming'] : false, + isset($this->_optionTemplates[$name]['frontendBackendAutoload']) ? $this->_optionTemplates[$name]['frontendBackendAutoload'] : false + ); + return $this->_caches[$name]; + } + } + + /** + * Set a named configuration template from which a cache object can later + * be lazy loaded + * + * @param string $name + * @param array $options + * @return Zend_Cache_Manager + */ + public function setCacheTemplate($name, $options) + { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } elseif (!is_array($options)) { + // require_once 'Zend/Cache/Exception.php'; + throw new Zend_Cache_Exception('Options passed must be in' + . ' an associative array or instance of Zend_Config'); + } + $this->_optionTemplates[$name] = $options; + return $this; + } + + /** + * Check if the named configuration template + * + * @param string $name + * @return bool + */ + public function hasCacheTemplate($name) + { + if (isset($this->_optionTemplates[$name])) { + return true; + } + return false; + } + + /** + * Get the named configuration template + * + * @param string $name + * @return array + */ + public function getCacheTemplate($name) + { + if (isset($this->_optionTemplates[$name])) { + return $this->_optionTemplates[$name]; + } + } + + /** + * Pass an array containing changes to be applied to a named + * configuration + * template + * + * @param string $name + * @param array $options + * @return Zend_Cache_Manager + * @throws Zend_Cache_Exception for invalid options format or if option templates do not have $name + */ + public function setTemplateOptions($name, $options) + { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } elseif (!is_array($options)) { + // require_once 'Zend/Cache/Exception.php'; + throw new Zend_Cache_Exception('Options passed must be in' + . ' an associative array or instance of Zend_Config'); + } + if (!isset($this->_optionTemplates[$name])) { + throw new Zend_Cache_Exception('A cache configuration template' + . 'does not exist with the name "' . $name . '"'); + } + $this->_optionTemplates[$name] + = $this->_mergeOptions($this->_optionTemplates[$name], $options); + return $this; + } + + /** + * Simple method to merge two configuration arrays + * + * @param array $current + * @param array $options + * @return array + */ + protected function _mergeOptions(array $current, array $options) + { + if (isset($options['frontend']['name'])) { + $current['frontend']['name'] = $options['frontend']['name']; + } + if (isset($options['backend']['name'])) { + $current['backend']['name'] = $options['backend']['name']; + } + if (isset($options['frontend']['options'])) { + foreach ($options['frontend']['options'] as $key=>$value) { + $current['frontend']['options'][$key] = $value; + } + } + if (isset($options['backend']['options'])) { + foreach ($options['backend']['options'] as $key=>$value) { + $current['backend']['options'][$key] = $value; + } + } + return $current; + } +} |