26 #require_once 'Zend/Cache/Backend/ExtendedInterface.php'; 31 #require_once 'Zend/Cache/Backend.php'; 100 'file_locking' =>
true,
101 'read_control' =>
true,
102 'read_control_type' =>
'crc32',
103 'hashed_directory_level' => 0,
104 'hashed_directory_perm' => 0700,
105 'file_name_prefix' =>
'zend_cache',
106 'cache_file_perm' => 0600,
107 'metadatas_array_max_size' => 100
127 if ($this->_options[
'cache_dir'] !==
null) {
130 $this->
setCacheDir(self::getTmpDir() . DIRECTORY_SEPARATOR,
false);
132 if (isset($this->_options[
'file_name_prefix'])) {
133 if (!preg_match(
'~^[a-zA-Z0-9_]+$~D', $this->_options[
'file_name_prefix'])) {
137 if ($this->_options[
'metadatas_array_max_size'] < 10) {
141 if (isset(
$options[
'hashed_directory_umask'])) {
143 trigger_error(
"'hashed_directory_umask' is deprecated -> please use 'hashed_directory_perm' instead", E_USER_NOTICE);
144 if (!isset(
$options[
'hashed_directory_perm'])) {
148 if (isset(
$options[
'hashed_directory_perm']) && is_string(
$options[
'hashed_directory_perm'])) {
150 $this->_options[
'hashed_directory_perm'] = octdec($this->_options[
'hashed_directory_perm']);
153 if (isset(
$options[
'cache_file_umask'])) {
155 trigger_error(
"'cache_file_umask' is deprecated -> please use 'cache_file_perm' instead", E_USER_NOTICE);
156 if (!isset(
$options[
'cache_file_perm'])) {
160 if (isset(
$options[
'cache_file_perm']) && is_string(
$options[
'cache_file_perm'])) {
162 $this->_options[
'cache_file_perm'] = octdec($this->_options[
'cache_file_perm']);
182 if ($trailingSeparator) {
184 $value = rtrim(realpath(
$value),
'\\/') . DIRECTORY_SEPARATOR;
186 $this->_options[
'cache_dir'] =
$value;
196 public function load(
$id, $doNotTestCacheValidity =
false)
198 if (!($this->
_test(
$id, $doNotTestCacheValidity))) {
205 if ($this->_options[
'read_control']) {
206 $hashData = $this->
_hash(
$data, $this->_options[
'read_control_type']);
207 $hashControl = $metadatas[
'hash'];
208 if ($hashData != $hashControl) {
210 $this->
_log(
'Zend_Cache_Backend_File::load() / read_control : stored hash and computed hash do not match');
242 public function save(
$data,
$id, $tags = array(), $specificLifetime =
false)
247 if ($this->_options[
'hashed_directory_level'] > 0) {
256 if ($this->_options[
'read_control']) {
257 $hash = $this->
_hash(
$data, $this->_options[
'read_control_type']);
269 $this->
_log(
'Zend_Cache_Backend_File::save() / error on saving metadata');
282 public function remove(
$id)
285 $boolRemove = $this->
_remove($file);
287 return $boolMetadata && $boolRemove;
312 return $this->
_clean($this->_options[
'cache_dir'],
$mode, $tags);
322 return $this->
_get($this->_options[
'cache_dir'],
'ids', array());
332 return $this->
_get($this->_options[
'cache_dir'],
'tags', array());
345 return $this->
_get($this->_options[
'cache_dir'],
'matching', $tags);
358 return $this->
_get($this->_options[
'cache_dir'],
'notMatching', $tags);
371 return $this->
_get($this->_options[
'cache_dir'],
'matchingAny', $tags);
383 $total = disk_total_space($this->_options[
'cache_dir']);
387 if ($free >= $total) {
390 return ((
int) (100. * ($total - $free) / $total));
411 if (
time() > $metadatas[
'expire']) {
415 'expire' => $metadatas[
'expire'],
416 'tags' => $metadatas[
'tags'],
417 'mtime' => $metadatas[
'mtime']
434 if (
time() > $metadatas[
'expire']) {
437 $newMetadatas = array(
438 'hash' => $metadatas[
'hash'],
440 'expire' => $metadatas[
'expire'] + $extraLifetime,
441 'tags' => $metadatas[
'tags']
467 'automatic_cleaning' =>
true,
469 'expired_read' =>
true,
471 'infinite_lifetime' =>
true,
487 $metadatas[
'expire'] = 1;
500 if (isset($this->_metadatasArray[
$id])) {
501 return $this->_metadatasArray[
$id];
522 if (count($this->_metadatasArray) >= $this->_options[
'metadatas_array_max_size']) {
523 $n = (int) ($this->_options[
'metadatas_array_max_size'] / 10);
524 $this->_metadatasArray = array_slice($this->_metadatasArray, $n);
532 $this->_metadatasArray[
$id] = $metadatas;
544 if (isset($this->_metadatasArray[
$id])) {
545 unset($this->_metadatasArray[
$id]);
558 $this->_metadatasArray = array();
617 if (substr(
$id, 0, 21) ==
'internal-metadatas---') {
639 # we can't remove the file (because of locks or any problem) 640 $this->
_log(
"Zend_Cache_Backend_File::_remove() : we can't remove $file");
671 $prefix = $this->_options[
'file_name_prefix'];
672 $glob = @glob($dir .
$prefix .
'--*');
673 if ($glob ===
false) {
677 $metadataFiles = array();
678 foreach ($glob as $file) {
685 $metadataFiles[] = $file;
691 if ($metadatas === FALSE) {
692 $metadatas = array(
'expire' => 1,
'tags' => array());
699 if (
time() > $metadatas[
'expire']) {
705 foreach ($tags as $tag) {
706 if (!in_array($tag, $metadatas[
'tags'])) {
717 foreach ($tags as $tag) {
718 if (in_array($tag, $metadatas[
'tags'])) {
729 foreach ($tags as $tag) {
730 if (in_array($tag, $metadatas[
'tags'])) {
744 if ((
is_dir($file)) and ($this->_options[
'hashed_directory_level']>0)) {
755 foreach ($metadataFiles as $file) {
756 if (file_exists($file)) {
770 $prefix = $this->_options[
'file_name_prefix'];
771 $glob = @glob($dir .
$prefix .
'--*');
772 if ($glob ===
false) {
776 foreach ($glob as $file) {
781 if ($metadatas === FALSE) {
784 if (
time() > $metadatas[
'expire']) {
796 foreach ($tags as $tag) {
797 if (!in_array($tag, $metadatas[
'tags'])) {
808 foreach ($tags as $tag) {
809 if (in_array($tag, $metadatas[
'tags'])) {
820 foreach ($tags as $tag) {
821 if (in_array($tag, $metadatas[
'tags'])) {
835 if ((
is_dir($file)) and ($this->_options[
'hashed_directory_level']>0)) {
837 $recursiveRs = $this->
_get($file . DIRECTORY_SEPARATOR,
$mode, $tags);
838 if ($recursiveRs ===
false) {
839 $this->
_log(
'Zend_Cache_Backend_File::_get() / recursive call : can\'t list entries of "'.$file.
'"');
856 if ($lifetime ===
null) {
859 return time() + $lifetime;
872 switch ($controlType) {
878 return strlen(
$data);
880 return hash(
'adler32',
$data);
894 $prefix = $this->_options[
'file_name_prefix'];
921 $partsArray = array();
922 $root = $this->_options[
'cache_dir'];
923 $prefix = $this->_options[
'file_name_prefix'];
924 if ($this->_options[
'hashed_directory_level']>0) {
925 $hash = hash(
'adler32',
$id);
926 for (
$i=0 ;
$i < $this->_options[
'hashed_directory_level'] ;
$i++) {
927 $root = $root .
$prefix .
'--' . substr($hash, 0,
$i + 1) . DIRECTORY_SEPARATOR;
928 $partsArray[] = $root;
946 if ($this->_options[
'hashed_directory_level'] <=0) {
949 $partsArray = $this->
_path(
$id,
true);
950 foreach ($partsArray as $part) {
952 @
mkdir($part, $this->_options[
'hashed_directory_perm']);
953 @
chmod($part, $this->_options[
'hashed_directory_perm']);
966 protected function _test(
$id, $doNotTestCacheValidity)
972 if ($doNotTestCacheValidity || (
time() <= $metadatas[
'expire'])) {
973 return $metadatas[
'mtime'];
990 $f = @
fopen($file,
'rb');
992 if ($this->_options[
'file_locking']) @flock($f, LOCK_SH);
993 $result = stream_get_contents($f);
994 if ($this->_options[
'file_locking']) @flock($f, LOCK_UN);
1010 $f = @
fopen($file,
'ab+');
1012 if ($this->_options[
'file_locking']) @flock($f, LOCK_EX);
1015 $tmp = @
fwrite($f, $string);
1016 if (!($tmp === FALSE)) {
1021 @
chmod($file, $this->_options[
'cache_file_perm']);
1033 $prefix = $this->_options[
'file_name_prefix'];
clean($mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array())
getIdsNotMatchingTags($tags=array())
setCacheDir($value, $trailingSeparator=true)
_get($dir, $mode, $tags=array())
_clean($dir, $mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array())
touch($id, $extraLifetime)
_log($message, $priority=4)
_test($id, $doNotTestCacheValidity)
_filePutContents($file, $string)
_isMetadatasFile($fileName)
const CLEANING_MODE_NOT_MATCHING_TAG
_saveMetadatas($id, $metadatas)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
__construct(array $options=array())
static throwException($msg, Exception $e=null)
getIdsMatchingTags($tags=array())
mkdir($pathname, $mode=0777, $recursive=false, $context=null)
const CLEANING_MODE_MATCHING_ANY_TAG
save($data, $id, $tags=array(), $specificLifetime=false)
_recursiveMkdirAndChmod($id)
_setMetadatas($id, $metadatas, $save=true)
const CLEANING_MODE_MATCHING_TAG
getIdsMatchingAnyTags($tags=array())
load($id, $doNotTestCacheValidity=false)
getLifetime($specificLifetime)
_hash($data, $controlType)