Issue

ZF-9705: TwoLevels backend doesn't update fast cache if full

Issue Type: Bug Created: 2010-04-19T00:28:53.000+0000 Last Updated: 2010-04-19T12:19:47.000+0000 Status: Closed Fix version(s): - 1.10.4 (28/Apr/10)

Reporter: Niko Sams (nikosams) Assignee: Marc Bennewitz (private) (mabe) Tags: - Zend_Cache

Related issues: Attachments: - test.diff

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)

Comments

Posted by Niko Sams (nikosams) on 2010-04-19T00:30:05.000+0000

unit test

Posted by Marc Bennewitz (private) (mabe) on 2010-04-19T12:19:46.000+0000

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

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2017 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts