27 #require_once 'Zend/Cache/Backend/ExtendedInterface.php'; 32 #require_once 'Zend/Cache/Backend.php'; 86 'slow_backend' =>
'File',
87 'fast_backend' =>
'Apc',
88 'slow_backend_options' => array(),
89 'fast_backend_options' => array(),
90 'stats_update_factor' => 10,
91 'slow_backend_custom_naming' =>
false,
92 'fast_backend_custom_naming' =>
false,
93 'slow_backend_autoload' =>
false,
94 'fast_backend_autoload' =>
false,
95 'auto_fill_fast_cache' =>
true,
96 'auto_refresh_fast_cache' =>
true 131 if ($this->_options[
'slow_backend'] ===
null) {
134 $this->_slowBackend = $this->_options[
'slow_backend'];
137 $this->_options[
'slow_backend'],
138 $this->_options[
'slow_backend_options'],
139 $this->_options[
'slow_backend_custom_naming'],
140 $this->_options[
'slow_backend_autoload']
142 if (!in_array(
'Zend_Cache_Backend_ExtendedInterface', class_implements($this->_slowBackend))) {
147 if ($this->_options[
'fast_backend'] ===
null) {
150 $this->_fastBackend = $this->_options[
'fast_backend'];
153 $this->_options[
'fast_backend'],
154 $this->_options[
'fast_backend_options'],
155 $this->_options[
'fast_backend_custom_naming'],
156 $this->_options[
'fast_backend_autoload']
158 if (!in_array(
'Zend_Cache_Backend_ExtendedInterface', class_implements($this->_fastBackend))) {
163 $this->_slowBackend->setDirectives($this->_directives);
164 $this->_fastBackend->setDirectives($this->_directives);
175 $fastTest = $this->_fastBackend->test(
$id);
179 return $this->_slowBackend->test(
$id);
196 public function save(
$data,
$id, $tags = array(), $specificLifetime =
false, $priority = 8)
198 $usage = $this->_getFastFillingPercentage(
'saving');
201 $preparedData = $this->_prepareData(
$data, $lifetime, $priority);
202 if (($priority > 0) && (10 * $priority >= $usage)) {
203 $fastLifetime = $this->_getFastLifetime($lifetime, $priority);
204 $boolFast = $this->_fastBackend->save($preparedData,
$id, array(), $fastLifetime);
205 $boolSlow = $this->_slowBackend->save($preparedData,
$id, $tags, $lifetime);
207 $boolSlow = $this->_slowBackend->save($preparedData,
$id, $tags, $lifetime);
208 if ($boolSlow ===
true) {
209 $boolFast = $this->_fastBackend->remove(
$id);
210 if (!$boolFast && !$this->_fastBackend->test(
$id)) {
218 return ($boolFast && $boolSlow);
230 public function load(
$id, $doNotTestCacheValidity =
false)
232 $resultFast = $this->_fastBackend->load(
$id, $doNotTestCacheValidity);
233 if ($resultFast ===
false) {
234 $resultSlow = $this->_slowBackend->load(
$id, $doNotTestCacheValidity);
235 if ($resultSlow ===
false) {
240 $array = $resultFast !==
false ? unserialize($resultFast) : unserialize($resultSlow);
243 if ($resultFast ===
false && $this->_options[
'auto_fill_fast_cache']) {
244 $preparedData = $this->_prepareData($array[
'data'], $array[
'lifetime'], $array[
'priority']);
245 $this->_fastBackend->save($preparedData,
$id, array(), $array[
'lifetime']);
248 elseif ($this->_options[
'auto_refresh_fast_cache']) {
249 if ($array[
'priority'] == 10) {
251 return $array[
'data'];
253 $newFastLifetime = $this->_getFastLifetime($array[
'lifetime'], $array[
'priority'],
time() - $array[
'expire']);
255 $usage = $this->_getFastFillingPercentage(
'loading');
256 if (($array[
'priority'] > 0) && (10 * $array[
'priority'] >= $usage)) {
258 $preparedData = $this->_prepareData($array[
'data'], $array[
'lifetime'], $array[
'priority']);
259 $this->_fastBackend->save($preparedData,
$id, array(), $newFastLifetime);
262 return $array[
'data'];
271 public function remove(
$id)
273 $boolFast = $this->_fastBackend->remove(
$id);
274 $boolSlow = $this->_slowBackend->remove(
$id);
275 return $boolFast && $boolSlow;
302 return $boolFast && $boolSlow;
307 $ids = $this->_slowBackend->getIdsMatchingTags($tags);
309 foreach ($ids as
$id) {
310 $bool = $this->
remove(
$id);
311 $res = $res && $bool;
316 $ids = $this->_slowBackend->getIdsNotMatchingTags($tags);
318 foreach ($ids as
$id) {
319 $bool = $this->
remove(
$id);
320 $res = $res && $bool;
325 $ids = $this->_slowBackend->getIdsMatchingAnyTags($tags);
327 foreach ($ids as
$id) {
328 $bool = $this->
remove(
$id);
329 $res = $res && $bool;
346 return $this->_slowBackend->getIds();
356 return $this->_slowBackend->getTags();
369 return $this->_slowBackend->getIdsMatchingTags($tags);
382 return $this->_slowBackend->getIdsNotMatchingTags($tags);
395 return $this->_slowBackend->getIdsMatchingAnyTags($tags);
405 return $this->_slowBackend->getFillingPercentage();
421 return $this->_slowBackend->getMetadatas(
$id);
433 return $this->_slowBackend->touch(
$id, $extraLifetime);
452 $slowBackendCapabilities = $this->_slowBackend->getCapabilities();
454 'automatic_cleaning' => $slowBackendCapabilities[
'automatic_cleaning'],
455 'tags' => $slowBackendCapabilities[
'tags'],
456 'expired_read' => $slowBackendCapabilities[
'expired_read'],
457 'priority' => $slowBackendCapabilities[
'priority'],
458 'infinite_lifetime' => $slowBackendCapabilities[
'infinite_lifetime'],
459 'get_list' => $slowBackendCapabilities[
'get_list']
471 private function _prepareData(
$data, $lifetime, $priority)
477 return serialize(array(
479 'lifetime' => $lifetime,
480 'expire' =>
time() + $lt,
481 'priority' => $priority
493 private function _getFastLifetime($lifetime, $priority, $maxLifetime =
null)
495 if ($lifetime <= 0) {
498 $fastLifetime = (int) (2592000 / (11 - $priority));
501 $fastLifetime = (int) ceil($lifetime / (11 - $priority));
504 if ($maxLifetime >= 0 && $fastLifetime > $maxLifetime) {
508 return $fastLifetime;
520 $this->_fastBackend->remove(
$id);
521 $this->_slowBackend->___expire(
$id);
524 private function _getFastFillingPercentage(
$mode)
527 if (
$mode ==
'saving') {
529 if ($this->_fastBackendFillingPercentage ===
null) {
530 $this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
532 $rand = rand(1, $this->_options[
'stats_update_factor']);
535 $this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
541 if ($this->_fastBackendFillingPercentage ===
null) {
542 $this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
elseif(isset( $params[ 'redirect_parent']))
getIdsMatchingAnyTags($tags=array())
clean($mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array())
const CLEANING_MODE_NOT_MATCHING_TAG
__construct(array $options=array())
load($id, $doNotTestCacheValidity=false)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
static throwException($msg, Exception $e=null)
getIdsMatchingTags($tags=array())
const CLEANING_MODE_MATCHING_ANY_TAG
touch($id, $extraLifetime)
const CLEANING_MODE_MATCHING_TAG
$_fastBackendFillingPercentage
getLifetime($specificLifetime)
save($data, $id, $tags=array(), $specificLifetime=false, $priority=8)
getIdsNotMatchingTags($tags=array())
static _makeBackend($backend, $backendOptions, $customBackendNaming=false, $autoload=false)