ZF-4614: Zend_Cache_Backend_Memcached infinite lifetime

Description

Zend_Cache_Backend_Memcached doesn't transform 'null' lifetime to '0' to have an infinite lifetime.

Find hereby a patch proposal:


--- Zend/Cache/Backend/Memcached.php    (revision 764)
+++ Zend/Cache/Backend/Memcached.php    (working copy)
@@ -167,6 +167,13 @@
     public function save($data, $id, $tags = array(), $specificLifetime = false)
     {
         $lifetime = $this->getLifetime($specificLifetime);
+        if ($lifetime > 2592000) {
+            # ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
+            $this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
+        } elseif (is_null($lifetime)) {
+           // For the memcached backend, we need a lifetime of 0 for infinite lifetime instead of null
+           $lifetime = 0;
+        }
         if ($this->_options['compression']) {
             $flag = MEMCACHE_COMPRESSED;
         } else {
@@ -230,21 +237,4 @@
     {
         return false;
     }
-
-    /**
-     * Set the frontend directives
-     *
-     * @param  array $directives Assoc of directives
-     * @throws Zend_Cache_Exception
-     * @return void
-     */
-    public function setDirectives($directives)
-    {
-        parent::setDirectives($directives);
-        $lifetime = $this->getLifetime(false);
-        if ($lifetime > 2592000) {
-            # ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
-            $this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
-        }
-    }
 }

Comments

see ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)

so we should transform null to 2592000 (instead of 0), shouldn't we ?

I think you should stay with null to 0. This is value expected by PHP's Memcache module.

Maybe the people from Memcached ships a new version supporting a longer lifetime, this way, passing 0 will guarantee the max allowed lifetime without changing the code.

commited in svn trunk

Changing issues in preparation for the 1.7.0 release.