import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -105,10 +105,9 @@ class Zend_Cache_Backend
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
}
|
||||
$name = strtolower($name);
|
||||
if (!array_key_exists($name, $this->_options)) {
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
if (array_key_exists($name, $this->_options)) {
|
||||
$this->_options[$name] = $value;
|
||||
}
|
||||
$this->_options[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,42 +131,85 @@ class Zend_Cache_Backend
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* DEPRECATED : use getCapabilities() instead
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @deprecated
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a system-wide tmp directory
|
||||
* Determine system TMP directory and detect if we have read access
|
||||
*
|
||||
* @return string System-wide tmp directory
|
||||
* inspired from Zend_File_Transfer_Adapter_Abstract
|
||||
*
|
||||
* @return string
|
||||
* @throws Zend_Cache_Exception if unable to determine directory
|
||||
*/
|
||||
static function getTmpDir()
|
||||
public function getTmpDir()
|
||||
{
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
// windows...
|
||||
foreach (array($_ENV, $_SERVER) as $tab) {
|
||||
foreach (array('TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
|
||||
if (isset($tab[$key])) {
|
||||
$result = $tab[$key];
|
||||
if (($key == 'windir') or ($key == 'SystemRoot')) {
|
||||
$result = $result . '\\temp';
|
||||
}
|
||||
return $result;
|
||||
$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')) {
|
||||
$dir = realpath($tab[$key] . '\\temp');
|
||||
} else {
|
||||
$dir = realpath($tab[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return '\\temp';
|
||||
} else {
|
||||
// unix...
|
||||
if (isset($_ENV['TMPDIR'])) return $_ENV['TMPDIR'];
|
||||
if (isset($_SERVER['TMPDIR'])) return $_SERVER['TMPDIR'];
|
||||
return '/tmp';
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$upload = ini_get('upload_tmp_dir');
|
||||
if ($upload) {
|
||||
$dir = realpath($upload);
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
if (function_exists('sys_get_temp_dir')) {
|
||||
$dir = sys_get_temp_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));
|
||||
unlink($tempFile);
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
if ($this->_isGoodTmpDir('/tmp')) {
|
||||
return '/tmp';
|
||||
}
|
||||
if ($this->_isGoodTmpDir('\\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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,8 +233,12 @@ class Zend_Cache_Backend
|
||||
} catch (Zend_Exception $e) {
|
||||
Zend_Cache::throwException('Logging feature is enabled but the Zend_Log class is not available');
|
||||
}
|
||||
if (isset($this->_directives['logger']) && $this->_directives['logger'] instanceof Zend_Log) {
|
||||
return;
|
||||
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.');
|
||||
}
|
||||
}
|
||||
// Create a default logger to the standard output stream
|
||||
require_once 'Zend/Log/Writer/Stream.php';
|
||||
@ -212,11 +258,14 @@ class Zend_Cache_Backend
|
||||
if (!$this->_directives['logging']) {
|
||||
return;
|
||||
}
|
||||
if (!(isset($this->_directives['logger']) || $this->_directives['logger'] instanceof Zend_Log)) {
|
||||
Zend_Cache::throwException('Logging is enabled but logger is not set');
|
||||
|
||||
if (!isset($this->_directives['logger'])) {
|
||||
Zend_Cache::throwException('Logging is enabled but logger is not set.');
|
||||
}
|
||||
$logger = $this->_directives['logger'];
|
||||
if (!$logger instanceof Zend_Log) {
|
||||
Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
|
||||
}
|
||||
$logger->log($message, $priority);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
parent::__construct($options);
|
||||
if (!is_null($this->_options['cache_dir'])) { // particular case for this option
|
||||
if ($this->_options['cache_dir'] !== null) { // particular case for this option
|
||||
$this->setCacheDir($this->_options['cache_dir']);
|
||||
} else {
|
||||
$this->setCacheDir(self::getTmpDir() . DIRECTORY_SEPARATOR, false);
|
||||
@ -284,17 +284,17 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
clearstatcache();
|
||||
return $this->_clean($this->_options['cache_dir'], $mode, $tags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
return $this->_get($this->_options['cache_dir'], 'ids', array());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
@ -304,10 +304,10 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
{
|
||||
return $this->_get($this->_options['cache_dir'], 'tags', 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
|
||||
@ -317,23 +317,23 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
{
|
||||
return $this->_get($this->_options['cache_dir'], 'matching', $tags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 $this->_get($this->_options['cache_dir'], 'notMatching', $tags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -343,7 +343,7 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
{
|
||||
return $this->_get($this->_options['cache_dir'], 'matchingAny', $tags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
@ -363,7 +363,7 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
return ((int) (100. * ($total - $free) / $total));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
@ -371,7 +371,7 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
* - 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)
|
||||
*/
|
||||
@ -390,7 +390,7 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
'mtime' => $metadatas['mtime']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
@ -419,10 +419,10 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
}
|
||||
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)
|
||||
@ -431,7 +431,7 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
* - 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()
|
||||
@ -726,7 +726,7 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
private function _get($dir, $mode, $tags = array())
|
||||
{
|
||||
if (!is_dir($dir)) {
|
||||
@ -812,7 +812,7 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
*/
|
||||
private function _expireTime($lifetime)
|
||||
{
|
||||
if (is_null($lifetime)) {
|
||||
if ($lifetime === null) {
|
||||
return 9999999999;
|
||||
}
|
||||
return time() + $lifetime;
|
||||
@ -893,10 +893,10 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
return $root;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make the directory strucuture for the given id
|
||||
*
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true
|
||||
*/
|
||||
@ -907,14 +907,14 @@ class Zend_Cache_Backend_File extends Zend_Cache_Backend implements Zend_Cache_B
|
||||
}
|
||||
$partsArray = $this->_path($id, true);
|
||||
foreach ($partsArray as $part) {
|
||||
if (!is_dir($part)) {
|
||||
@mkdir($part, $this->_options['hashed_directory_umask']);
|
||||
@chmod($part, $this->_options['hashed_directory_umask']); // see #ZF-320 (this line is required in some configurations)
|
||||
}
|
||||
if (!is_dir($part)) {
|
||||
@mkdir($part, $this->_options['hashed_directory_umask']);
|
||||
@chmod($part, $this->_options['hashed_directory_umask']); // see #ZF-320 (this line is required in some configurations)
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if the given cache id is available (and still valid as a cache record)
|
||||
*
|
||||
|
@ -40,26 +40,23 @@ require_once 'Zend/Cache/Backend.php';
|
||||
class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Default Host IP Address or DNS
|
||||
*/
|
||||
const DEFAULT_HOST = '127.0.0.1';
|
||||
|
||||
/**
|
||||
* Default port
|
||||
*/
|
||||
const DEFAULT_PORT = 11211;
|
||||
|
||||
/**
|
||||
* Persistent
|
||||
* Default Values
|
||||
*/
|
||||
const DEFAULT_HOST = '127.0.0.1';
|
||||
const DEFAULT_PORT = 11211;
|
||||
const DEFAULT_PERSISTENT = true;
|
||||
const DEFAULT_WEIGHT = 1;
|
||||
const DEFAULT_TIMEOUT = 1;
|
||||
const DEFAULT_RETRY_INTERVAL = 15;
|
||||
const DEFAULT_STATUS = true;
|
||||
const DEFAULT_FAILURE_CALLBACK = null;
|
||||
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::clean() : tags are unsupported by the Memcached backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend';
|
||||
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
@ -68,19 +65,41 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
* 'host' => (string) : the name of the memcached server
|
||||
* 'port' => (int) : the port of the memcached server
|
||||
* 'persistent' => (bool) : use or not persistent connections to this memcached server
|
||||
* 'weight' => (int) : number of buckets to create for this server which in turn control its
|
||||
* probability of it being selected. The probability is relative to the total
|
||||
* weight of all servers.
|
||||
* 'timeout' => (int) : value in seconds which will be used for connecting to the daemon. Think twice
|
||||
* before changing the default value of 1 second - you can lose all the
|
||||
* advantages of caching if your connection is too slow.
|
||||
* 'retry_interval' => (int) : controls how often a failed server will be retried, the default value
|
||||
* is 15 seconds. Setting this parameter to -1 disables automatic retry.
|
||||
* 'status' => (bool) : controls if the server should be flagged as online.
|
||||
* 'failure_callback' => (callback) : Allows the user to specify a callback function to run upon
|
||||
* encountering an error. The callback is run before failover
|
||||
* is attempted. The function takes two parameters, the hostname
|
||||
* and port of the failed server.
|
||||
*
|
||||
* =====> (boolean) compression :
|
||||
* true if you want to use on-the-fly compression
|
||||
*
|
||||
* =====> (boolean) compatibility :
|
||||
* true if you use old memcache server or extension
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'servers' => array(array(
|
||||
'host' => Zend_Cache_Backend_Memcached::DEFAULT_HOST,
|
||||
'port' => Zend_Cache_Backend_Memcached::DEFAULT_PORT,
|
||||
'persistent' => Zend_Cache_Backend_Memcached::DEFAULT_PERSISTENT
|
||||
'host' => self::DEFAULT_HOST,
|
||||
'port' => self::DEFAULT_PORT,
|
||||
'persistent' => self::DEFAULT_PERSISTENT,
|
||||
'weight' => self::DEFAULT_WEIGHT,
|
||||
'timeout' => self::DEFAULT_TIMEOUT,
|
||||
'retry_interval' => self::DEFAULT_RETRY_INTERVAL,
|
||||
'status' => self::DEFAULT_STATUS,
|
||||
'failure_callback' => self::DEFAULT_FAILURE_CALLBACK
|
||||
)),
|
||||
'compression' => false
|
||||
'compression' => false,
|
||||
'compatibility' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
@ -113,13 +132,38 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
}
|
||||
$this->_memcache = new Memcache;
|
||||
foreach ($this->_options['servers'] as $server) {
|
||||
if (!array_key_exists('persistent', $server)) {
|
||||
$server['persistent'] = Zend_Cache_Backend_Memcached::DEFAULT_PERSISTENT;
|
||||
}
|
||||
if (!array_key_exists('port', $server)) {
|
||||
$server['port'] = Zend_Cache_Backend_Memcached::DEFAULT_PORT;
|
||||
$server['port'] = self::DEFAULT_PORT;
|
||||
}
|
||||
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent']);
|
||||
if (!array_key_exists('persistent', $server)) {
|
||||
$server['persistent'] = self::DEFAULT_PERSISTENT;
|
||||
}
|
||||
if (!array_key_exists('weight', $server)) {
|
||||
$server['weight'] = self::DEFAULT_WEIGHT;
|
||||
}
|
||||
if (!array_key_exists('timeout', $server)) {
|
||||
$server['timeout'] = self::DEFAULT_TIMEOUT;
|
||||
}
|
||||
if (!array_key_exists('retry_interval', $server)) {
|
||||
$server['retry_interval'] = self::DEFAULT_RETRY_INTERVAL;
|
||||
}
|
||||
if (!array_key_exists('status', $server)) {
|
||||
$server['status'] = self::DEFAULT_STATUS;
|
||||
}
|
||||
if (!array_key_exists('failure_callback', $server)) {
|
||||
$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'],
|
||||
$server['weight'], $server['timeout'],
|
||||
$server['retry_interval']);
|
||||
} else {
|
||||
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
|
||||
$server['weight'], $server['timeout'],
|
||||
$server['retry_interval'],
|
||||
$server['status'], $server['failure_callback']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,10 +218,8 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
} else {
|
||||
$flag = 0;
|
||||
}
|
||||
if ($this->test($id)) {
|
||||
// because set and replace seems to have different behaviour
|
||||
$result = $this->_memcache->replace($id, array($data, time(), $lifetime), $flag, $lifetime);
|
||||
} else {
|
||||
// #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);
|
||||
}
|
||||
if (count($tags) > 0) {
|
||||
@ -257,15 +299,15 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
// #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
|
||||
$this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
|
||||
}
|
||||
if (is_null($lifetime)) {
|
||||
// #ZF-4614 : we tranform null to zero to get the maximal lifetime
|
||||
parent::setDirectives(array('lifetime' => 0));
|
||||
if ($lifetime === null) {
|
||||
// #ZF-4614 : we tranform null to zero to get the maximal lifetime
|
||||
parent::setDirectives(array('lifetime' => 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
@ -273,7 +315,7 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
$this->_log("Zend_Cache_Backend_Memcached::save() : getting the list of cache ids is unsupported by the Memcache backend");
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
@ -284,10 +326,10 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_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
|
||||
@ -301,21 +343,21 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
|
||||
/**
|
||||
* 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_MEMCACHED_BACKEND);
|
||||
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
|
||||
@ -324,7 +366,7 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -335,15 +377,29 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mem = $this->_memcache->getStats();
|
||||
$memSize = $mem['limit_maxbytes'];
|
||||
$memUsed= $mem['bytes'];
|
||||
if ($memSize == 0) {
|
||||
Zend_Cache::throwException('can\'t get memcache memory size');
|
||||
}
|
||||
if ($memUsed > $memSize) {
|
||||
return 100;
|
||||
$mems = $this->_memcache->getExtendedStats();
|
||||
|
||||
$memSize = 0;
|
||||
$memUsed = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
@ -354,7 +410,7 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
* - 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)
|
||||
*/
|
||||
@ -376,9 +432,9 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
@ -405,22 +461,20 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
if ($this->test($id)) {
|
||||
// because set and replace seems to have different behaviour
|
||||
$result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $flag, $newLifetime);
|
||||
} else {
|
||||
$result = $this->_memcache->set($id, array($data, time(), $newLifetime), $flag, $newLifetime);
|
||||
// #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);
|
||||
}
|
||||
return true;
|
||||
return $result;
|
||||
}
|
||||
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)
|
||||
@ -429,7 +483,7 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
* - 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()
|
||||
@ -443,5 +497,5 @@ class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Ca
|
||||
'get_list' => false
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
parent::__construct($options);
|
||||
if (is_null($this->_options['cache_db_complete_path'])) {
|
||||
if ($this->_options['cache_db_complete_path'] === null) {
|
||||
Zend_Cache::throwException('cache_db_complete_path option has to set');
|
||||
}
|
||||
if (!extension_loaded('sqlite')) {
|
||||
@ -161,7 +161,7 @@ class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$data = @sqlite_escape_string($data);
|
||||
$mktime = time();
|
||||
if (is_null($lifetime)) {
|
||||
if ($lifetime === null) {
|
||||
$expire = 0;
|
||||
} else {
|
||||
$expire = $mktime + $lifetime;
|
||||
@ -221,10 +221,10 @@ class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache
|
||||
$this->_automaticVacuum();
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
@ -237,7 +237,7 @@ class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
@ -253,10 +253,10 @@ class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -292,12 +292,12 @@ class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache
|
||||
|
||||
/**
|
||||
* 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())
|
||||
{
|
||||
$res = $this->_query("SELECT id FROM cache");
|
||||
@ -322,10 +322,10 @@ class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -387,7 +387,7 @@ class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache
|
||||
* - 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)
|
||||
*/
|
||||
@ -413,7 +413,7 @@ class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache
|
||||
'expire' => $row['expire']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
@ -437,10 +437,10 @@ class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache
|
||||
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)
|
||||
@ -449,7 +449,7 @@ class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache
|
||||
* - 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()
|
||||
|
@ -44,12 +44,12 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
* Available options
|
||||
*
|
||||
* =====> (string) slow_backend :
|
||||
* - Slow backend name
|
||||
* - Slow backend name
|
||||
* - Must implement the Zend_Cache_Backend_ExtendedInterface
|
||||
* - Should provide a big storage
|
||||
*
|
||||
* =====> (string) fast_backend :
|
||||
* - Flow backend name
|
||||
* - Flow backend name
|
||||
* - Must implement the Zend_Cache_Backend_ExtendedInterface
|
||||
* - Must be much faster than slow_backend
|
||||
*
|
||||
@ -58,22 +58,22 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
*
|
||||
* =====> (array) fast_backend_options :
|
||||
* - Fast backend options (see corresponding backend)
|
||||
*
|
||||
*
|
||||
* =====> (int) stats_update_factor :
|
||||
* - Disable / Tune the computation of the fast backend filling percentage
|
||||
* - When saving a record into cache :
|
||||
* 1 => systematic computation of the fast backend filling percentage
|
||||
* x (integer) > 1 => computation of the fast backend filling percentage randomly 1 times on x cache write
|
||||
*
|
||||
*
|
||||
* =====> (boolean) slow_backend_custom_naming :
|
||||
* =====> (boolean) fast_backend_custom_naming :
|
||||
* =====> (boolean) slow_backend_autoload :
|
||||
* =====> (boolean) fast_backend_autoload :
|
||||
* - See Zend_Cache::factory() method
|
||||
*
|
||||
* - See Zend_Cache::factory() method
|
||||
*
|
||||
* =====> (boolean) auto_refresh_fast_cache
|
||||
* - If true, auto refresh the fast cache when a cache record is hit
|
||||
*
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
@ -88,28 +88,28 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
'fast_backend_autoload' => false,
|
||||
'auto_refresh_fast_cache' => true
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Slow Backend
|
||||
*
|
||||
* @var Zend_Cache_Backend
|
||||
*/
|
||||
private $_slowBackend;
|
||||
|
||||
|
||||
/**
|
||||
* Fast Backend
|
||||
*
|
||||
* @var Zend_Cache_Backend
|
||||
*/
|
||||
private $_fastBackend;
|
||||
|
||||
|
||||
/**
|
||||
* Cache for the fast backend filling percentage
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_fastBackendFillingPercentage = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@ -120,24 +120,24 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
parent::__construct($options);
|
||||
if (is_null($this->_options['slow_backend'])) {
|
||||
if ($this->_options['slow_backend'] === null) {
|
||||
Zend_Cache::throwException('slow_backend option has to set');
|
||||
}
|
||||
if (is_null($this->_options['fast_backend'])) {
|
||||
if ($this->_options['fast_backend'] === null) {
|
||||
Zend_Cache::throwException('fast_backend option has to set');
|
||||
}
|
||||
}
|
||||
$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']);
|
||||
$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('slow_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
|
||||
}
|
||||
Zend_Cache::throwException('fast_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
|
||||
}
|
||||
$this->_slowBackend->setDirectives($this->_directives);
|
||||
$this->_fastBackend->setDirectives($this->_directives);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
@ -153,7 +153,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
return $this->_slowBackend->test($id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
@ -164,7 +164,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
* @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)
|
||||
* @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 boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false, $priority = 8)
|
||||
@ -180,7 +180,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
$boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime);
|
||||
return ($boolFast && $boolSlow);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
@ -212,13 +212,13 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
$usage = $this->_getFastFillingPercentage('loading');
|
||||
if (($array['priority'] > 0) && (10 * $array['priority'] >= $usage)) {
|
||||
// we can refresh the fast cache
|
||||
$preparedData = $this->_prepareData($array['data'], $array['lifetime'], $array['priority']);
|
||||
$preparedData = $this->_prepareData($array['data'], $array['lifetime'], $array['priority']);
|
||||
$this->_fastBackend->save($preparedData, $id, array(), $newFastLifetime);
|
||||
}
|
||||
}
|
||||
return $array['data'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
@ -230,7 +230,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
$this->_fastBackend->remove($id);
|
||||
return $this->_slowBackend->remove($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
@ -249,7 +249,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
@ -288,17 +288,17 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
return $this->_slowBackend->getIds();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
@ -308,10 +308,10 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
{
|
||||
return $this->_slowBackend->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
|
||||
@ -324,12 +324,12 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
|
||||
/**
|
||||
* 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 $this->_slowBackend->getIdsNotMatchingTags($tags);
|
||||
@ -337,7 +337,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -347,8 +347,8 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
{
|
||||
return $this->_slowBackend->getIdsMatchingAnyTags($tags);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
@ -366,7 +366,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
* - 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)
|
||||
*/
|
||||
@ -374,7 +374,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
{
|
||||
return $this->_slowBackend->getMetadatas($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
@ -386,10 +386,10 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
{
|
||||
return $this->_slowBackend->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)
|
||||
@ -398,7 +398,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
* - 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()
|
||||
@ -413,7 +413,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
'get_list' => $slowBackendCapabilities['get_list']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepare a serialized array to store datas and metadatas informations
|
||||
*
|
||||
@ -425,7 +425,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
private function _prepareData($data, $lifetime, $priority)
|
||||
{
|
||||
$lt = $lifetime;
|
||||
if (is_null($lt)) {
|
||||
if ($lt === null) {
|
||||
$lt = 9999999999;
|
||||
}
|
||||
return serialize(array(
|
||||
@ -435,7 +435,7 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
'priority' => $priority
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compute and return the lifetime for the fast backend
|
||||
*
|
||||
@ -446,21 +446,21 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
*/
|
||||
private function _getFastLifetime($lifetime, $priority, $maxLifetime = null)
|
||||
{
|
||||
if (is_null($lifetime)) {
|
||||
if ($lifetime === null) {
|
||||
// if lifetime is null, we have an infinite lifetime
|
||||
// we need to use arbitrary lifetimes
|
||||
$fastLifetime = (int) (2592000 / (11 - $priority));
|
||||
} else {
|
||||
$fastLifetime = (int) ($lifetime / (11 - $priority));
|
||||
}
|
||||
if (!is_null($maxLifetime) && ($maxLifetime >= 0)) {
|
||||
if (($maxLifetime !== null) && ($maxLifetime >= 0)) {
|
||||
if ($fastLifetime > $maxLifetime) {
|
||||
return $maxLifetime;
|
||||
}
|
||||
}
|
||||
return $fastLifetime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* PUBLIC METHOD FOR UNIT TESTING ONLY !
|
||||
*
|
||||
@ -471,15 +471,15 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
public function ___expire($id)
|
||||
{
|
||||
$this->_fastBackend->remove($id);
|
||||
$this->_slowBackend->___expire($id);
|
||||
}
|
||||
|
||||
$this->_slowBackend->___expire($id);
|
||||
}
|
||||
|
||||
private function _getFastFillingPercentage($mode)
|
||||
{
|
||||
|
||||
|
||||
if ($mode == 'saving') {
|
||||
// mode saving
|
||||
if (is_null($this->_fastBackendFillingPercentage)) {
|
||||
if ($this->_fastBackendFillingPercentage === null) {
|
||||
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
|
||||
} else {
|
||||
$rand = rand(1, $this->_options['stats_update_factor']);
|
||||
@ -491,11 +491,11 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
|
||||
} else {
|
||||
// mode loading
|
||||
// we compute the percentage only if it's not available in cache
|
||||
if (is_null($this->_fastBackendFillingPercentage)) {
|
||||
if ($this->_fastBackendFillingPercentage === null) {
|
||||
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
|
||||
}
|
||||
}
|
||||
return $this->_fastBackendFillingPercentage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ class Zend_Cache_Backend_ZendPlatform extends Zend_Cache_Backend implements Zend
|
||||
$result = ($this->_remove($file)) && ($result);
|
||||
} else if ($mode == Zend_Cache::CLEANING_MODE_OLD) {
|
||||
// Files older than lifetime get deleted from cache
|
||||
if (!is_null($this->_directives['lifetime'])) {
|
||||
if ($this->_directives['lifetime'] !== null) {
|
||||
if ((time() - @filemtime($file)) > $this->_directives['lifetime']) {
|
||||
$result = ($this->_remove($file)) && ($result);
|
||||
}
|
||||
@ -302,7 +302,7 @@ class Zend_Cache_Backend_ZendPlatform extends Zend_Cache_Backend implements Zend
|
||||
# If we can't remove the file (because of locks or any problem), we will touch
|
||||
# the file to invalidate it
|
||||
$this->_log("Zend_Cache_Backend_ZendPlatform::_remove() : we can't remove $file => we are going to try to invalidate it");
|
||||
if (is_null($this->_directives['lifetime'])) {
|
||||
if ($this->_directives['lifetime'] === null) {
|
||||
return false;
|
||||
}
|
||||
if (!file_exists($file)) {
|
||||
|
208
libs/Zend/Cache/Backend/ZendServer.php
Executable file
208
libs/Zend/Cache/Backend/ZendServer.php
Executable file
@ -0,0 +1,208 @@
|
||||
<?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-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** @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-2008 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
|
||||
{
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (string) namespace :
|
||||
* Namespace to be used for chaching operations
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'namespace' => 'zendframework'
|
||||
);
|
||||
|
||||
/**
|
||||
* Store data
|
||||
*
|
||||
* @var mixed $data Object to store
|
||||
* @var string $id Cache id
|
||||
* @var int $timeToLive Time to live in seconds
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
abstract protected function _store($data, $id, $timeToLive);
|
||||
|
||||
/**
|
||||
* Fetch data
|
||||
*
|
||||
* @var mixed $data Object to store
|
||||
* @var string $id Cache id
|
||||
* @var int $timeToLive Time to live in seconds
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
abstract protected function _fetch($id);
|
||||
|
||||
/**
|
||||
* Unset data
|
||||
*
|
||||
* @var string $id Cache id
|
||||
*/
|
||||
abstract protected function _unset($id);
|
||||
|
||||
/**
|
||||
* Clear cache
|
||||
*/
|
||||
abstract protected function _clear();
|
||||
|
||||
/**
|
||||
* 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 cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = $this->_fetch($id);
|
||||
if ($tmp !== null) {
|
||||
return $tmp;
|
||||
}
|
||||
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
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = $this->_fetch('internal-metadatas---' . $id);
|
||||
if ($tmp !== null) {
|
||||
if (!is_array($tmp) || !isset($tmp['mtime'])) {
|
||||
Zend_Cache::throwException('Cache metadata for \'' . $id . '\' id is corrupted' );
|
||||
}
|
||||
return $tmp['mtime'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute & return the expire time
|
||||
*
|
||||
* @return int expire time (unix timestamp)
|
||||
*/
|
||||
private function _expireTime($lifetime)
|
||||
{
|
||||
if ($lifetime === null) {
|
||||
return 9999999999;
|
||||
}
|
||||
return time() + $lifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$metadatas = array(
|
||||
'mtime' => time(),
|
||||
'expire' => $this->_expireTime($lifetime),
|
||||
);
|
||||
|
||||
if (count($tags) > 0) {
|
||||
$this->_log('Zend_Cache_Backend_ZendServer::save() : tags are unsupported by the ZendServer backends');
|
||||
}
|
||||
|
||||
return $this->_store($data, $id, $lifetime) &&
|
||||
$this->_store($metadatas, 'internal-metadatas---' . $id, $lifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
$result1 = $this->_unset($id);
|
||||
$result2 = $this->_unset('internal-metadatas---' . $id);
|
||||
|
||||
return $result1 && $result2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param array $tags array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
$this->_clear();
|
||||
return true;
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_ZendServer::clean() : CLEANING_MODE_OLD is unsupported by the Zend Server backends.");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_clear();
|
||||
$this->_log('Zend_Cache_Backend_ZendServer::clean() : tags are unsupported by the Zend Server backends.');
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
101
libs/Zend/Cache/Backend/ZendServer/Disk.php
Executable file
101
libs/Zend/Cache/Backend/ZendServer/Disk.php
Executable file
@ -0,0 +1,101 @@
|
||||
<?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-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** @see Zend_Cache_Backend_Interface */
|
||||
require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/** @see Zend_Cache_Backend_ZendServer */
|
||||
require_once 'Zend/Cache/Backend/ZendServer.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2008 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
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!function_exists('zend_disk_cache_store')) {
|
||||
Zend_Cache::throwException('Zend_Cache_ZendServer_Disk backend has to be used within Zend Server environment.');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data
|
||||
*
|
||||
* @var mixed $data Object to store
|
||||
* @var string $id Cache id
|
||||
* @var int $timeToLive Time to live in seconds
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
protected function _store($data, $id, $timeToLive)
|
||||
{
|
||||
if (zend_disk_cache_store($this->_options['namespace'] . '::' . $id,
|
||||
$data,
|
||||
$timeToLive) === false) {
|
||||
$this->_log('Store operation failed.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data
|
||||
*
|
||||
* @var mixed $data Object to store
|
||||
* @var string $id Cache id
|
||||
* @var int $timeToLive Time to live in seconds
|
||||
*/
|
||||
protected function _fetch($id)
|
||||
{
|
||||
return zend_disk_cache_fetch($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset data
|
||||
*
|
||||
* @var string $id Cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
protected function _unset($id)
|
||||
{
|
||||
return zend_disk_cache_delete($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache
|
||||
*/
|
||||
protected function _clear()
|
||||
{
|
||||
zend_disk_cache_clear($this->_options['namespace']);
|
||||
}
|
||||
}
|
101
libs/Zend/Cache/Backend/ZendServer/ShMem.php
Executable file
101
libs/Zend/Cache/Backend/ZendServer/ShMem.php
Executable file
@ -0,0 +1,101 @@
|
||||
<?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-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** @see Zend_Cache_Backend_Interface */
|
||||
require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/** @see Zend_Cache_Backend_ZendServer */
|
||||
require_once 'Zend/Cache/Backend/ZendServer.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2008 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
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!function_exists('zend_shm_cache_store')) {
|
||||
Zend_Cache::throwException('Zend_Cache_ZendServer_ShMem backend has to be used within Zend Server environment.');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data
|
||||
*
|
||||
* @var mixed $data Object to store
|
||||
* @var string $id Cache id
|
||||
* @var int $timeToLive Time to live in seconds
|
||||
*
|
||||
*/
|
||||
protected function _store($data, $id, $timeToLive)
|
||||
{
|
||||
if (zend_shm_cache_store($this->_options['namespace'] . '::' . $id,
|
||||
$data,
|
||||
$timeToLive) === false) {
|
||||
$this->_log('Store operation failed.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch data
|
||||
*
|
||||
* @var mixed $data Object to store
|
||||
* @var string $id Cache id
|
||||
* @var int $timeToLive Time to live in seconds
|
||||
*/
|
||||
protected function _fetch($id)
|
||||
{
|
||||
return zend_shm_cache_fetch($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset data
|
||||
*
|
||||
* @var string $id Cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
protected function _unset($id)
|
||||
{
|
||||
return zend_shm_cache_delete($this->_options['namespace'] . '::' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache
|
||||
*/
|
||||
protected function _clear()
|
||||
{
|
||||
zend_shm_cache_clear($this->_options['namespace']);
|
||||
}
|
||||
}
|
@ -105,7 +105,7 @@ class Zend_Cache_Core
|
||||
* @var string $_lastId
|
||||
*/
|
||||
private $_lastId = null;
|
||||
|
||||
|
||||
/**
|
||||
* True if the backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
*
|
||||
@ -115,11 +115,11 @@ class Zend_Cache_Core
|
||||
|
||||
/**
|
||||
* Array of capabilities of the backend (only if it implements Zend_Cache_Backend_ExtendedInterface)
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_backendCapabilities = array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@ -156,7 +156,7 @@ class Zend_Cache_Core
|
||||
$this->_extendedBackend = true;
|
||||
$this->_backendCapabilities = $this->_backend->getCapabilities();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,20 +181,20 @@ class Zend_Cache_Core
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if (is_string($name)) {
|
||||
$name = strtolower($name);
|
||||
if (array_key_exists($name, $this->_options)) {
|
||||
// This is a Core option
|
||||
$this->_setOption($name, $value);
|
||||
return;
|
||||
}
|
||||
if (array_key_exists($name, $this->_specificOptions)) {
|
||||
// This a specic option of this frontend
|
||||
$this->_specificOptions[$name] = $value;
|
||||
return;
|
||||
}
|
||||
if (!is_string($name)) {
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
}
|
||||
$name = strtolower($name);
|
||||
if (array_key_exists($name, $this->_options)) {
|
||||
// This is a Core option
|
||||
$this->_setOption($name, $value);
|
||||
return;
|
||||
}
|
||||
if (array_key_exists($name, $this->_specificOptions)) {
|
||||
// This a specic option of this frontend
|
||||
$this->_specificOptions[$name] = $value;
|
||||
return;
|
||||
}
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -304,7 +304,7 @@ class Zend_Cache_Core
|
||||
* @param string $id Cache id (if not set, the last cache id will be used)
|
||||
* @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
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
@ -313,7 +313,7 @@ class Zend_Cache_Core
|
||||
if (!$this->_options['caching']) {
|
||||
return true;
|
||||
}
|
||||
if (is_null($id)) {
|
||||
if ($id === null) {
|
||||
$id = $this->_lastId;
|
||||
} else {
|
||||
$id = $this->_id($id);
|
||||
@ -428,10 +428,10 @@ class Zend_Cache_Core
|
||||
self::_validateTagsArray($tags);
|
||||
return $this->_backend->clean($mode, $tags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -447,15 +447,15 @@ class Zend_Cache_Core
|
||||
}
|
||||
return $this->_backend->getIdsMatchingTags($tags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 (!$this->_extendedBackend) {
|
||||
@ -466,10 +466,10 @@ class Zend_Cache_Core
|
||||
}
|
||||
return $this->_backend->getIdsNotMatchingTags($tags);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
@ -477,9 +477,20 @@ class Zend_Cache_Core
|
||||
if (!$this->_extendedBackend) {
|
||||
Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available');
|
||||
}
|
||||
return $this->_backend->getIds();
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
@ -493,9 +504,9 @@ class Zend_Cache_Core
|
||||
if (!($this->_backendCapabilities['tags'])) {
|
||||
Zend_Cache::throwException('tags are not supported by the current backend');
|
||||
}
|
||||
return $this->_backend->getTags();
|
||||
return $this->_backend->getTags();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
@ -506,9 +517,9 @@ class Zend_Cache_Core
|
||||
if (!$this->_extendedBackend) {
|
||||
Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available');
|
||||
}
|
||||
return $this->_backend->getFillingPercentage();
|
||||
return $this->_backend->getFillingPercentage();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
@ -521,9 +532,10 @@ class Zend_Cache_Core
|
||||
if (!$this->_extendedBackend) {
|
||||
Zend_Cache::throwException('Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available');
|
||||
}
|
||||
return $this->_backend->touch($id, $extraLifetime);
|
||||
$id = $this->_id($id); // cache id may need prefix
|
||||
return $this->_backend->touch($id, $extraLifetime);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate a cache id or a tag (security, reliable filenames, reserved prefixes...)
|
||||
*
|
||||
@ -533,7 +545,7 @@ class Zend_Cache_Core
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
private static function _validateIdOrTag($string)
|
||||
protected static function _validateIdOrTag($string)
|
||||
{
|
||||
if (!is_string($string)) {
|
||||
Zend_Cache::throwException('Invalid id or tag : must be a string');
|
||||
@ -555,7 +567,7 @@ class Zend_Cache_Core
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
private static function _validateTagsArray($tags)
|
||||
protected static function _validateTagsArray($tags)
|
||||
{
|
||||
if (!is_array($tags)) {
|
||||
Zend_Cache::throwException('Invalid tags array : must be an array');
|
||||
@ -579,17 +591,11 @@ class Zend_Cache_Core
|
||||
if (!isset($this->_options['logging']) || !$this->_options['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->_options['logger']) && $this->_options['logger'] instanceof Zend_Log) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a default logger to the standard output stream
|
||||
require_once 'Zend/Log/Writer/Stream.php';
|
||||
$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
|
||||
@ -623,9 +629,9 @@ class Zend_Cache_Core
|
||||
* @param string $id Cache id
|
||||
* @return string Cache id (with or without prefix)
|
||||
*/
|
||||
private function _id($id)
|
||||
protected function _id($id)
|
||||
{
|
||||
if (!is_null($id) && isset($this->_options['cache_id_prefix'])) {
|
||||
if (($id !== null) && isset($this->_options['cache_id_prefix'])) {
|
||||
return $this->_options['cache_id_prefix'] . $id; // return with prefix
|
||||
}
|
||||
return $id; // no prefix, just return the $id passed
|
||||
|
@ -89,7 +89,7 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
|
||||
* @var string
|
||||
*/
|
||||
private $_cachedEntityLabel = '';
|
||||
|
||||
|
||||
/**
|
||||
* Priority (used by some particular backends)
|
||||
*
|
||||
@ -109,7 +109,7 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
|
||||
while (list($name, $value) = each($options)) {
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
if (is_null($this->_specificOptions['cached_entity'])) {
|
||||
if ($this->_specificOptions['cached_entity'] === null) {
|
||||
Zend_Cache::throwException('cached_entity must be set !');
|
||||
}
|
||||
$this->setCachedEntity($this->_specificOptions['cached_entity']);
|
||||
@ -125,18 +125,18 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
|
||||
public function setSpecificLifetime($specificLifetime = false)
|
||||
{
|
||||
$this->_specificLifetime = $specificLifetime;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the priority (used by some particular backends)
|
||||
*
|
||||
*
|
||||
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority)
|
||||
*/
|
||||
public function setPriority($priority)
|
||||
{
|
||||
$this->_priority = $priority;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Public frontend to set an option
|
||||
*
|
||||
@ -155,14 +155,14 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
|
||||
parent::setOption($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specific method to set the cachedEntity
|
||||
*
|
||||
*
|
||||
* if set to a class name, we will cache an abstract class and will use only static calls
|
||||
* if set to an object, we will cache this object methods
|
||||
*
|
||||
* @param mixed $cachedEntity
|
||||
*
|
||||
* @param mixed $cachedEntity
|
||||
*/
|
||||
public function setCachedEntity($cachedEntity)
|
||||
{
|
||||
|
@ -34,25 +34,49 @@ require_once 'Zend/Cache/Core.php';
|
||||
*/
|
||||
class Zend_Cache_Frontend_File extends Zend_Cache_Core
|
||||
{
|
||||
|
||||
/**
|
||||
* Consts for master_files_mode
|
||||
*/
|
||||
const MODE_AND = 'AND';
|
||||
const MODE_OR = 'OR';
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* ====> (string) master_file :
|
||||
* - the complete path and name of the 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 false (default), an exception is thrown if there is a missing master file
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_specificOptions = array(
|
||||
'master_file' => ''
|
||||
'master_file' => null,
|
||||
'master_files' => null,
|
||||
'master_files_mode' => 'OR',
|
||||
'ignore_missing_master_files' => false
|
||||
);
|
||||
|
||||
/**
|
||||
* Master file mtime
|
||||
* Master file mtimes
|
||||
*
|
||||
* @var int
|
||||
* Array of int
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_masterFile_mtime = null;
|
||||
private $_masterFile_mtimes = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -66,10 +90,9 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core
|
||||
while (list($name, $value) = each($options)) {
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
if (!isset($this->_specificOptions['master_file'])) {
|
||||
Zend_Cache::throwException('master_file option must be set');
|
||||
if (!isset($this->_specificOptions['master_files'])) {
|
||||
Zend_Cache::throwException('master_files option must be set');
|
||||
}
|
||||
$this->setMasterFile($this->_specificOptions['master_file']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,15 +100,35 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core
|
||||
*
|
||||
* @param string $masterFile the complete path and name of the master file
|
||||
*/
|
||||
public function setMasterFile($masterFile)
|
||||
public function setMasterFiles($masterFiles)
|
||||
{
|
||||
clearstatcache();
|
||||
$this->_specificOptions['master_file'] = $masterFile;
|
||||
if (!($this->_masterFile_mtime = @filemtime($masterFile))) {
|
||||
Zend_Cache::throwException('Unable to read master_file : '.$masterFile);
|
||||
$this->_specificOptions['master_file'] = $masterFiles[0]; // to keep a compatibility
|
||||
$this->_specificOptions['master_files'] = $masterFiles;
|
||||
$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++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the master_file option
|
||||
*
|
||||
* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Public frontend to set an option
|
||||
*
|
||||
@ -100,6 +143,8 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core
|
||||
{
|
||||
if ($name == 'master_file') {
|
||||
$this->setMasterFile($value);
|
||||
} else if ($name == 'master_files') {
|
||||
$this->setMasterFiles($value);
|
||||
} else {
|
||||
parent::setOption($name, $value);
|
||||
}
|
||||
@ -134,9 +179,27 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core
|
||||
{
|
||||
$lastModified = parent::test($id);
|
||||
if ($lastModified) {
|
||||
if ($lastModified > $this->_masterFile_mtime) {
|
||||
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;
|
||||
}
|
||||
|
@ -81,19 +81,19 @@ class Zend_Cache_Frontend_Output extends Zend_Cache_Core
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @param string $forcedDatas If not null, force written datas with this
|
||||
* @param boolean $echoData If set to true, datas are sent to the browser
|
||||
* @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 void
|
||||
*/
|
||||
public function end($tags = array(), $specificLifetime = false, $forcedDatas = null, $echoData = true, $priority = 8)
|
||||
{
|
||||
if (is_null($forcedDatas)) {
|
||||
if ($forcedDatas === null) {
|
||||
$data = ob_get_contents();
|
||||
ob_end_clean();
|
||||
} else {
|
||||
$data =& $forcedDatas;
|
||||
}
|
||||
$id = array_pop($this->_idStack);
|
||||
if (is_null($id)) {
|
||||
if ($id === null) {
|
||||
Zend_Cache::throwException('use of end() without a start()');
|
||||
}
|
||||
$this->save($data, $id, $tags, $specificLifetime, $priority);
|
||||
|
@ -63,12 +63,12 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core
|
||||
* - (boolean) makeIdWithXXXVariables (XXXX = 'Get', 'Post', 'Session', 'Files' or 'Cookie') :
|
||||
* if true, we have to use the content of this superglobal array to make a cache id
|
||||
* if false, the cache id won't be dependent of the content of this superglobal array
|
||||
* - (int) specific_lifetime : cache specific lifetime
|
||||
* (false => global lifetime is used, null => infinite lifetime,
|
||||
* integer => this lifetime is used), this "lifetime" is probably only
|
||||
* - (int) specific_lifetime : cache specific lifetime
|
||||
* (false => global lifetime is used, null => infinite lifetime,
|
||||
* integer => this lifetime is used), this "lifetime" is probably only
|
||||
* usefull when used with "regexps" array
|
||||
* - (array) tags : array of tags (strings)
|
||||
* - (int) priority : integer between 0 (very low priority) and 10 (maximum priority) used by
|
||||
* - (array) tags : array of tags (strings)
|
||||
* - (int) priority : integer between 0 (very low priority) and 10 (maximum priority) used by
|
||||
* some particular backends
|
||||
*
|
||||
* ====> (array) regexps :
|
||||
@ -116,7 +116,7 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_cancel = false;
|
||||
protected $_cancel = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -131,17 +131,17 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core
|
||||
while (list($name, $value) = each($options)) {
|
||||
$name = strtolower($name);
|
||||
switch ($name) {
|
||||
case 'regexps':
|
||||
$this->_setRegexps($value);
|
||||
break;
|
||||
case 'default_options':
|
||||
$this->_setDefaultOptions($value);
|
||||
break;
|
||||
case 'content_type_memorization':
|
||||
$this->_setContentTypeMemorization($value);
|
||||
break;
|
||||
default:
|
||||
$this->setOption($name, $value);
|
||||
case 'regexps':
|
||||
$this->_setRegexps($value);
|
||||
break;
|
||||
case 'default_options':
|
||||
$this->_setDefaultOptions($value);
|
||||
break;
|
||||
case 'content_type_memorization':
|
||||
$this->_setContentTypeMemorization($value);
|
||||
break;
|
||||
default:
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
}
|
||||
if (isset($this->_specificOptions['http_conditional'])) {
|
||||
@ -165,10 +165,11 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core
|
||||
Zend_Cache::throwException('default_options must be an array !');
|
||||
}
|
||||
foreach ($options as $key=>$value) {
|
||||
if (!is_string($key)) {
|
||||
Zend_Cache::throwException("invalid option [$key] !");
|
||||
}
|
||||
$key = strtolower($key);
|
||||
if (!isset($this->_specificOptions['default_options'][$key])) {
|
||||
Zend_Cache::throwException("unknown option [$key] !");
|
||||
} else {
|
||||
if (isset($this->_specificOptions['default_options'][$key])) {
|
||||
$this->_specificOptions['default_options'][$key] = $value;
|
||||
}
|
||||
}
|
||||
@ -218,9 +219,12 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core
|
||||
}
|
||||
$validKeys = array_keys($this->_specificOptions['default_options']);
|
||||
foreach ($conf as $key=>$value) {
|
||||
if (!is_string($key)) {
|
||||
Zend_Cache::throwException("unknown option [$key] !");
|
||||
}
|
||||
$key = strtolower($key);
|
||||
if (!in_array($key, $validKeys)) {
|
||||
Zend_Cache::throwException("unknown option [$key] !");
|
||||
unset($regexps[$regexp][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -244,7 +248,7 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core
|
||||
}
|
||||
}
|
||||
$this->_activeOptions = $this->_specificOptions['default_options'];
|
||||
if (!is_null($lastMatchingRegexp)) {
|
||||
if ($lastMatchingRegexp !== null) {
|
||||
$conf = $this->_specificOptions['regexps'][$lastMatchingRegexp];
|
||||
foreach ($conf as $key=>$value) {
|
||||
$this->_activeOptions[$key] = $value;
|
||||
@ -263,15 +267,15 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core
|
||||
if ($array !== false) {
|
||||
$data = $array['data'];
|
||||
$headers = $array['headers'];
|
||||
if ($this->_specificOptions['debug_header']) {
|
||||
echo 'DEBUG HEADER : This is a cached page !';
|
||||
}
|
||||
if (!headers_sent()) {
|
||||
foreach ($headers as $key=>$headerCouple) {
|
||||
$name = $headerCouple[0];
|
||||
$value = $headerCouple[1];
|
||||
header("$name: $value");
|
||||
}
|
||||
}
|
||||
if ($this->_specificOptions['debug_header']) {
|
||||
echo 'DEBUG HEADER : This is a cached page !';
|
||||
}
|
||||
echo $data;
|
||||
if ($doNotDie) {
|
||||
@ -316,7 +320,7 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core
|
||||
$storedHeaders[] = array($headerSentName, $headerSentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$array = array(
|
||||
'data' => $data,
|
||||
'headers' => $storedHeaders
|
||||
@ -333,8 +337,10 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core
|
||||
protected function _makeId()
|
||||
{
|
||||
$tmp = $_SERVER['REQUEST_URI'];
|
||||
$array = explode('?', $tmp, 2);
|
||||
$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;
|
||||
}
|
||||
@ -353,7 +359,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;
|
||||
|
Reference in New Issue
Block a user