Zend Framework

TwoLevels backend doesn't update fast cache if full

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.10.3
  • Fix Version/s: 1.10.4
  • Component/s: Zend_Cache
  • Labels:
    None

Description

The TwoLevels backend doesn't correctly update the fast cache, if it's full.
Attached unit test shows the problem.

Two possible solutions:

1. update fast if entry exists ignoring usage. (Assuming the old and new data will
have similar size)

Index: Zend/Cache/Backend/TwoLevels.php
===================================================================
--- Zend/Cache/Backend/TwoLevels.php    (revision 21942)
+++ Zend/Cache/Backend/TwoLevels.php    (working copy)
@@ -174,7 +174,7 @@
         $boolFast = true;
         $lifetime = $this->getLifetime($specificLifetime);
         $preparedData = $this->_prepareData($data, $lifetime, $priority);
-        if (($priority > 0) && (10 * $priority >= $usage)) {
+        if ((($priority > 0) && (10 * $priority >= $usage)) || $this->_fastBackend->test($id)) {
             $fastLifetime = $this->_getFastLifetime($lifetime, $priority);
             $boolFast = $this->_fastBackend->save($preparedData, $id, array(), $fastLifetime);
         }

2. when updating and an entry exists remove it

Index: Zend/Cache/Backend/TwoLevels.php
===================================================================
--- Zend/Cache/Backend/TwoLevels.php    (revision 21942)
+++ Zend/Cache/Backend/TwoLevels.php    (working copy)
@@ -177,6 +177,8 @@
         if (($priority > 0) && (10 * $priority >= $usage)) {
             $fastLifetime = $this->_getFastLifetime($lifetime, $priority);
             $boolFast = $this->_fastBackend->save($preparedData, $id, array(), $fastLifetime);
+        } else if ($this->_fastBackend->test($id)) {
+            $this->_fastBackend->remove($id);
         }
         $boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime);
         return ($boolFast && $boolSlow);

(Included in the unit test patch is a change to the TwoLevels backend constructor that allows giving
slow and fast backend directly as objects, just like Zend_Cache::factory does. This made it easier
to write the test using a mock object)

Activity

Hide
Niko Sams added a comment -

unit test

Show
Niko Sams added a comment - unit test
Hide
Marc Bennewitz (private) added a comment -

fixed in r21953 (trunk) & r21954 (1.10 branch)

Show
Marc Bennewitz (private) added a comment - fixed in r21953 (trunk) & r21954 (1.10 branch)

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: