Bug #9092: Horde_Cache_Base::set() no longer returns a boolean result
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 17 Jun 2010 21:56:24 +0000 (15:56 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 17 Jun 2010 21:56:32 +0000 (15:56 -0600)
14 files changed:
framework/Cache/lib/Horde/Cache/Apc.php
framework/Cache/lib/Horde/Cache/Base.php
framework/Cache/lib/Horde/Cache/Eaccelerator.php
framework/Cache/lib/Horde/Cache/File.php
framework/Cache/lib/Horde/Cache/Memcache.php
framework/Cache/lib/Horde/Cache/Mock.php
framework/Cache/lib/Horde/Cache/Null.php
framework/Cache/lib/Horde/Cache/Sql.php
framework/Cache/lib/Horde/Cache/Stack.php
framework/Cache/lib/Horde/Cache/Xcache.php
framework/Cache/package.xml
framework/Kolab_Storage/lib/Horde/Kolab/Storage.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php
framework/Template/lib/Horde/Template.php

index 83c1771..4860d33 100644 (file)
@@ -36,15 +36,13 @@ class Horde_Cache_Apc extends Horde_Cache_Base
      * @param string $key        Cache key (identifier).
      * @param mixed $data        Data to store in the cache.
      * @param integer $lifetime  Data lifetime.
-     *
-     * @return boolean  True on success, false on failure.
      */
     public function set($key, $data, $lifetime = null)
     {
         $key = $this->_params['prefix'] . $key;
         $lifetime = $this->_getLifetime($lifetime);
         apc_store($key . '_expire', time(), $lifetime);
-        return apc_store($key, $data, $lifetime);
+        apc_store($key, $data, $lifetime);
     }
 
     /**
index e5cf446..9faa3d5 100644 (file)
@@ -92,8 +92,6 @@ abstract class Horde_Cache_Base
      *                           data becomes available for garbage
      *                           collection.  If null use the default Horde GC
      *                           time.  If 0 will not be GC'd.
-     *
-     * @return boolean  True on success, false on failure.
      */
     abstract public function set($key, $data, $lifetime = null);
 
index a0919ed..93ff1c6 100644 (file)
@@ -50,15 +50,13 @@ class Horde_Cache_Eaccelerator extends Horde_Cache_Base
      * @param string $key        Cache key (identifier).
      * @param mixed $data        Data to store in the cache.
      * @param integer $lifetime  Data lifetime.
-     *
-     * @return boolean  True on success, false on failure.
      */
     public function set($key, $data, $lifetime = null)
     {
         $key = $this->_params['prefix'] . $key;
         $lifetime = $this->_getLifetime($lifetime);
         eaccelerator_put($key . '_expire', time(), $lifetime);
-        return eaccelerator_put($key, $data, $lifetime);
+        eaccelerator_put($key, $data, $lifetime);
     }
 
     /**
index 43b113f..e59e1dc 100644 (file)
@@ -136,8 +136,6 @@ class Horde_Cache_File extends Horde_Cache_Base
      * @param string $key        Cache key.
      * @param mixed $data        Data to store in the cache. (MUST BE A STRING)
      * @param integer $lifetime  Data lifetime.
-     *
-     * @return boolean  True on success, false on failure.
      */
     public function set($key, $data, $lifetime = null)
     {
@@ -148,7 +146,7 @@ class Horde_Cache_File extends Horde_Cache_Base
         }
 
         if (file_put_contents($tmp_file, $data) === false) {
-            return false;
+            return;
         }
 
         @rename($tmp_file, $filename);
@@ -162,8 +160,6 @@ class Horde_Cache_File extends Horde_Cache_Base
             fwrite($fp, $filename . "\t" . (empty($lifetime) ? 0 : time() + $lifetime) . "\n");
             fclose($fp);
         }
-
-        return true;
     }
 
     /**
index 364c8c1..ac199e5 100644 (file)
@@ -104,17 +104,15 @@ class Horde_Cache_Memcache extends Horde_Cache_Base
      * @param string $key        Cache key.
      * @param mixed $data        Data to store in the cache.
      * @param integer $lifetime  Data lifetime.
-     *
-     * @return boolean  True on success, false on failure.
      */
     public function set($key, $data, $lifetime = null)
     {
         $key = $this->_params['prefix'] . $key;
         $lifetime = $this->_getLifetime($lifetime);
 
-        return ($this->_memcache->set($key . '_e', time(), $lifetime) === false)
-            ? false
-            : $this->_memcache->set($key, $data, $lifetime);
+        if ($this->_memcache->set($key . '_e', time(), $lifetime) !== false) {
+            $this->_memcache->set($key, $data, $lifetime);
+        }
     }
 
     /**
index 55ee5e9..48fe8fa 100644 (file)
@@ -55,8 +55,6 @@ class Horde_Cache_Mock extends Horde_Cache_Base
      * @param string $key        Cache key (identifier).
      * @param mixed $data        Data to store in the cache.
      * @param integer $lifetime  Data lifetime.
-     *
-     * @return boolean  True on success, false on failure.
      */
     public function set($key, $data, $lifetime = null)
     {
index 06028fe..c8f7589 100644 (file)
@@ -34,12 +34,9 @@ class Horde_Cache_Null extends Horde_Cache_Base
      * @param string $key        Cache key (identifier).
      * @param mixed $data        Data to store in the cache.
      * @param integer $lifetime  Data lifetime.
-     *
-     * @return boolean  True on success, false on failure.
      */
     public function set($key, $data, $lifetime = null)
     {
-        return false;
     }
 
     /**
index d651e01..61c69f5 100644 (file)
@@ -139,8 +139,6 @@ class Horde_Cache_Sql extends Horde_Cache_Base
      * @param mixed $data        Data to store in the cache. (MUST BE A STRING)
      * @param integer $lifetime  Maximum data life span or 0 for a
      *                           non-expiring object.
-     *
-     * @return boolean  True on success, false on failure.
      */
     public function set($key, $data, $lifetime = null)
     {
@@ -154,15 +152,15 @@ class Horde_Cache_Sql extends Horde_Cache_Base
             ? 0
             : $this->_getLifetime($lifetime) + $timestamp;
 
-            if ($this->_logger) {
-                $this->_logger->log(sprintf('Cache set: %s (Id %s set at %d expires at %d)', $okey, $key, $timestamp, $expiration), 'DEBUG');
-            }
+        if ($this->_logger) {
+            $this->_logger->log(sprintf('Cache set: %s (Id %s set at %d expires at %d)', $okey, $key, $timestamp, $expiration), 'DEBUG');
+        }
 
         // Remove any old cache data and prevent duplicate keys
         $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE cache_id=?';
         $values = array($key);
         try {
-            $this->_db->query($query, $values);
+            $this->_db->delete($query, $values);
         } catch (Horde_Db_Exception $e) {}
 
         /* Build SQL query. */
@@ -172,12 +170,8 @@ class Horde_Cache_Sql extends Horde_Cache_Base
         $values = array($key, $timestamp, $expiration, $data);
 
         try {
-            $this->_db->query($query, $values);
-        } catch (Horde_Db_Exception $e) {
-            return false;
-        }
-
-        return true;
+            $this->_db->insert($query, $values);
+        } catch (Horde_Db_Exception $e) {}
     }
 
     /**
index 8cdc74b..434be71 100644 (file)
@@ -82,8 +82,6 @@ class Horde_Cache_Stack extends Horde_Cache_Base
      *                           data becomes available for garbage
      *                           collection.  If null use the default Horde GC
      *                           time.  If 0 will not be GC'd.
-     *
-     * @return boolean  True on success, false on failure.
      */
     public function set($key, $data, $lifetime = null)
     {
@@ -95,7 +93,7 @@ class Horde_Cache_Stack extends Horde_Cache_Base
             $result = $val->set($key, $data, $lifetime);
             if ($result === false) {
                 if ($master) {
-                    return false;
+                    return;
                 }
 
                 /* Attempt to invalidate cache if write failed. */
@@ -103,8 +101,6 @@ class Horde_Cache_Stack extends Horde_Cache_Base
             }
             $master = false;
         }
-
-        return true;
     }
 
     /**
index 1574845..60fdca3 100644 (file)
@@ -39,15 +39,13 @@ class Horde_Cache_Xcache extends Horde_Cache_Base
      * @param string $key        Cache key (identifier).
      * @param mixed $data        Data to store in the cache.
      * @param integer $lifetime  Data lifetime.
-     *
-     * @return boolean  True on success, false on failure.
      */
     public function set($key, $data, $lifetime = null)
     {
         $key = $this->_params['prefix'] . $key;
         $lifetime = $this->_getLifetime($lifetime);
         xcache_set($key . '_expire', time(), $lifetime);
-        return xcache_set($key, $data, $lifetime);
+        xcache_set($key, $data, $lifetime);
     }
 
     /**
index a0561cb..6952f37 100644 (file)
@@ -33,7 +33,8 @@ Performance Suite&apos;s content cache), memcached, or an SQL table.
   <api>beta</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Added Horde_Cache_Exception::.
+ <notes>* Horde_Cache_Base::set() no longer returns a boolean result.
+ * Added Horde_Cache_Exception::.
  * Removed dependency on Horde Core.
  * Initial Horde 4 package.</notes>
  <contents>
index 33c7011..252a9f2 100644 (file)
@@ -218,8 +218,8 @@ class Horde_Kolab_Storage
     protected function shutdown()
     {
         $data = @serialize($this);
-        return $this->_cache->set($signature, $data,
-                                  $GLOBALS['conf']['kolab']['storage']['cache']['folders']['lifetime']);
+        $this->_cache->set($signature, $data,
+                           $GLOBALS['conf']['kolab']['storage']['cache']['folders']['lifetime']);
     }
 
     /**
index 89dd80e..71b4319 100644 (file)
@@ -195,7 +195,8 @@ class Horde_Kolab_Storage_Cache
      */
     public function storeAttachment($key, $data)
     {
-        return $this->horde_cache->set($key, $data);
+        $this->horde_cache->set($key, $data);
+        return true;
     }
 
     /**
index 90ce4d1..abb6169 100644 (file)
@@ -240,11 +240,11 @@ class Horde_Template
         if ($force || is_null($this->_template)) {
             $this->_template = str_replace("\n", " \n", file_get_contents($file));
             $this->_parse();
-            if ($this->_cache &&
-                isset($cacheid) &&
-                !$this->_cache->set($cacheid, $this->_template) &&
-                $this->_logger) {
-                $this->_logger->log(sprintf('Could not save the compiled template file "%s".', $file), 'ERR');
+            if ($this->_cache && isset($cacheid)) {
+                $this->_cache->set($cacheid, $this->_template);
+                if ($this->_logger) {
+                    $this->_logger->log(sprintf('Saved compiled template file for "%s".', $file), 'DEBUG');
+                }
             }
         }