2020 * @version $Id$
2121 */
2222
23-
2423/**
2524 * @see Zend_Cache_Backend_ExtendedInterface
2625 */
3130 */
3231require_once 'Zend/Cache/Backend.php ' ;
3332
34-
3533/**
3634 * @package Zend_Cache
3735 * @subpackage Zend_Cache_Backend
3836 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
3937 * @license http://framework.zend.com/license/new-bsd New BSD License
4038 */
41-
4239class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
4340{
4441 /**
@@ -76,24 +73,24 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
7673 * - If true, automatically fill the fast cache when a cache record was not found in fast cache, but did
7774 * exist in slow cache. This can be usefull when a non-persistent cache like APC or Memcached got
7875 * purged for whatever reason.
79- *
76+ *
8077 * =====> (boolean) auto_refresh_fast_cache
8178 * - If true, auto refresh the fast cache when a cache record is hit
8279 *
8380 * @var array available options
8481 */
8582 protected $ _options = array (
86- 'slow_backend ' => 'File ' ,
87- 'fast_backend ' => 'Apc ' ,
88- 'slow_backend_options ' => array (),
89- 'fast_backend_options ' => array (),
90- 'stats_update_factor ' => 10 ,
83+ 'slow_backend ' => 'File ' ,
84+ 'fast_backend ' => 'Apc ' ,
85+ 'slow_backend_options ' => array (),
86+ 'fast_backend_options ' => array (),
87+ 'stats_update_factor ' => 10 ,
9188 'slow_backend_custom_naming ' => false ,
9289 '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
90+ 'slow_backend_autoload ' => false ,
91+ 'fast_backend_autoload ' => false ,
92+ 'auto_fill_fast_cache ' => true ,
93+ 'auto_refresh_fast_cache ' => true ,
9794 );
9895
9996 /**
@@ -121,8 +118,8 @@ class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Ca
121118 * Constructor
122119 *
123120 * @param array $options Associative array of options
121+ *
124122 * @throws Zend_Cache_Exception
125- * @return void
126123 */
127124 public function __construct (array $ options = array ())
128125 {
@@ -168,6 +165,7 @@ public function __construct(array $options = array())
168165 * Test if a cache is available or not (for the given id)
169166 *
170167 * @param string $id cache id
168+ *
171169 * @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
172170 */
173171 public function test ($ id )
@@ -186,11 +184,12 @@ public function test($id)
186184 * Note : $data is always "string" (serialization is done by the
187185 * core not by the backend)
188186 *
189- * @param string $data Datas to cache
190- * @param string $id Cache id
191- * @param array $tags Array of strings, the cache record will be tagged by each string entry
192- * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
193- * @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
187+ * @param string $data Datas to cache
188+ * @param string $id Cache id
189+ * @param array $tags Array of strings, the cache record will be tagged by each string entry
190+ * @param false|null|int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
191+ * @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
192+ *
194193 * @return boolean true if no problem
195194 */
196195 public function save ($ data , $ id , $ tags = array (), $ specificLifetime = false , $ priority = 8 )
@@ -225,6 +224,7 @@ public function save($data, $id, $tags = array(), $specificLifetime = false, $pr
225224 *
226225 * @param string $id Cache id
227226 * @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
227+ *
228228 * @return string|false cached datas
229229 */
230230 public function load ($ id , $ doNotTestCacheValidity = false )
@@ -259,19 +259,22 @@ public function load($id, $doNotTestCacheValidity = false)
259259 $ this ->_fastBackend ->save ($ preparedData , $ id , array (), $ newFastLifetime );
260260 }
261261 }
262+
262263 return $ array ['data ' ];
263264 }
264265
265266 /**
266267 * Remove a cache record
267268 *
268269 * @param string $id Cache id
270+ *
269271 * @return boolean True if no problem
270272 */
271273 public function remove ($ id )
272274 {
273275 $ boolFast = $ this ->_fastBackend ->remove ($ id );
274276 $ boolSlow = $ this ->_slowBackend ->remove ($ id );
277+
275278 return $ boolFast && $ boolSlow ;
276279 }
277280
@@ -290,15 +293,17 @@ public function remove($id)
290293 *
291294 * @param string $mode Clean mode
292295 * @param array $tags Array of tags
296+ *
293297 * @throws Zend_Cache_Exception
294298 * @return boolean true if no problem
295299 */
296300 public function clean ($ mode = Zend_Cache::CLEANING_MODE_ALL , $ tags = array ())
297301 {
298- switch ($ mode ) {
302+ switch ($ mode ) {
299303 case Zend_Cache::CLEANING_MODE_ALL :
300304 $ boolFast = $ this ->_fastBackend ->clean (Zend_Cache::CLEANING_MODE_ALL );
301305 $ boolSlow = $ this ->_slowBackend ->clean (Zend_Cache::CLEANING_MODE_ALL );
306+
302307 return $ boolFast && $ boolSlow ;
303308 break ;
304309 case Zend_Cache::CLEANING_MODE_OLD :
@@ -310,6 +315,7 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
310315 $ bool = $ this ->remove ($ id );
311316 $ res = $ res && $ bool ;
312317 }
318+
313319 return $ res ;
314320 break ;
315321 case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG :
@@ -319,6 +325,7 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
319325 $ bool = $ this ->remove ($ id );
320326 $ res = $ res && $ bool ;
321327 }
328+
322329 return $ res ;
323330 break ;
324331 case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG :
@@ -328,6 +335,7 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
328335 $ bool = $ this ->remove ($ id );
329336 $ res = $ res && $ bool ;
330337 }
338+
331339 return $ res ;
332340 break ;
333341 default :
@@ -414,6 +422,7 @@ public function getFillingPercentage()
414422 * - mtime : timestamp of last modification time
415423 *
416424 * @param string $id cache id
425+ *
417426 * @return array array of metadatas (false if the cache id is not found)
418427 */
419428 public function getMetadatas ($ id )
@@ -425,7 +434,8 @@ public function getMetadatas($id)
425434 * Give (if possible) an extra lifetime to the given cache id
426435 *
427436 * @param string $id cache id
428- * @param int $extraLifetime
437+ * @param int $extraLifetime
438+ *
429439 * @return boolean true if ok
430440 */
431441 public function touch ($ id , $ extraLifetime )
@@ -450,22 +460,24 @@ public function touch($id, $extraLifetime)
450460 public function getCapabilities ()
451461 {
452462 $ slowBackendCapabilities = $ this ->_slowBackend ->getCapabilities ();
463+
453464 return array (
454465 '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 ' ]
466+ 'tags ' => $ slowBackendCapabilities ['tags ' ],
467+ 'expired_read ' => $ slowBackendCapabilities ['expired_read ' ],
468+ 'priority ' => $ slowBackendCapabilities ['priority ' ],
469+ 'infinite_lifetime ' => $ slowBackendCapabilities ['infinite_lifetime ' ],
470+ 'get_list ' => $ slowBackendCapabilities ['get_list ' ],
460471 );
461472 }
462473
463474 /**
464475 * Prepare a serialized array to store datas and metadatas informations
465476 *
466- * @param string $data data to store
467- * @param int $lifetime original lifetime
468- * @param int $priority priority
477+ * @param string $data data to store
478+ * @param int $lifetime original lifetime
479+ * @param int $priority priority
480+ *
469481 * @return string serialize array to store into cache
470482 */
471483 private function _prepareData ($ data , $ lifetime , $ priority )
@@ -474,20 +486,22 @@ private function _prepareData($data, $lifetime, $priority)
474486 if ($ lt === null ) {
475487 $ lt = 9999999999 ;
476488 }
489+
477490 return serialize (array (
478- 'data ' => $ data ,
491+ 'data ' => $ data ,
479492 'lifetime ' => $ lifetime ,
480- 'expire ' => time () + $ lt ,
481- 'priority ' => $ priority
493+ 'expire ' => time () + $ lt ,
494+ 'priority ' => $ priority,
482495 ));
483496 }
484497
485498 /**
486499 * Compute and return the lifetime for the fast backend
487500 *
488- * @param int $lifetime original lifetime
489- * @param int $priority priority
501+ * @param int $lifetime original lifetime
502+ * @param int $priority priority
490503 * @param int $maxLifetime maximum lifetime
504+ *
491505 * @return int lifetime for the fast backend
492506 */
493507 private function _getFastLifetime ($ lifetime , $ priority , $ maxLifetime = null )
@@ -501,7 +515,7 @@ private function _getFastLifetime($lifetime, $priority, $maxLifetime = null)
501515 $ fastLifetime = (int ) ceil ($ lifetime / (11 - $ priority ));
502516 }
503517
504- if ($ maxLifetime >= 0 && $ fastLifetime > $ maxLifetime ) {
518+ if ($ maxLifetime > 0 && $ fastLifetime > $ maxLifetime ) {
505519 return $ maxLifetime ;
506520 }
507521
@@ -523,7 +537,6 @@ public function ___expire($id)
523537
524538 private function _getFastFillingPercentage ($ mode )
525539 {
526-
527540 if ($ mode == 'saving ' ) {
528541 // mode saving
529542 if ($ this ->_fastBackendFillingPercentage === null ) {
@@ -542,7 +555,7 @@ private function _getFastFillingPercentage($mode)
542555 $ this ->_fastBackendFillingPercentage = $ this ->_fastBackend ->getFillingPercentage ();
543556 }
544557 }
558+
545559 return $ this ->_fastBackendFillingPercentage ;
546560 }
547-
548561}
0 commit comments