import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -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