From eef3225fadfeb74e4c3550f2a2a7a6369f79a5c1 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 17 Jun 2010 15:56:24 -0600 Subject: [PATCH] Bug #9092: Horde_Cache_Base::set() no longer returns a boolean result --- framework/Cache/lib/Horde/Cache/Apc.php | 4 +--- framework/Cache/lib/Horde/Cache/Base.php | 2 -- framework/Cache/lib/Horde/Cache/Eaccelerator.php | 4 +--- framework/Cache/lib/Horde/Cache/File.php | 6 +----- framework/Cache/lib/Horde/Cache/Memcache.php | 8 +++----- framework/Cache/lib/Horde/Cache/Mock.php | 2 -- framework/Cache/lib/Horde/Cache/Null.php | 3 --- framework/Cache/lib/Horde/Cache/Sql.php | 18 ++++++------------ framework/Cache/lib/Horde/Cache/Stack.php | 6 +----- framework/Cache/lib/Horde/Cache/Xcache.php | 4 +--- framework/Cache/package.xml | 3 ++- framework/Kolab_Storage/lib/Horde/Kolab/Storage.php | 4 ++-- .../Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php | 3 ++- framework/Template/lib/Horde/Template.php | 10 +++++----- 14 files changed, 25 insertions(+), 52 deletions(-) diff --git a/framework/Cache/lib/Horde/Cache/Apc.php b/framework/Cache/lib/Horde/Cache/Apc.php index 83c177188..4860d33f0 100644 --- a/framework/Cache/lib/Horde/Cache/Apc.php +++ b/framework/Cache/lib/Horde/Cache/Apc.php @@ -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); } /** diff --git a/framework/Cache/lib/Horde/Cache/Base.php b/framework/Cache/lib/Horde/Cache/Base.php index e5cf4461d..9faa3d5ca 100644 --- a/framework/Cache/lib/Horde/Cache/Base.php +++ b/framework/Cache/lib/Horde/Cache/Base.php @@ -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); diff --git a/framework/Cache/lib/Horde/Cache/Eaccelerator.php b/framework/Cache/lib/Horde/Cache/Eaccelerator.php index a0919edf4..93ff1c692 100644 --- a/framework/Cache/lib/Horde/Cache/Eaccelerator.php +++ b/framework/Cache/lib/Horde/Cache/Eaccelerator.php @@ -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); } /** diff --git a/framework/Cache/lib/Horde/Cache/File.php b/framework/Cache/lib/Horde/Cache/File.php index 43b113f8a..e59e1dc96 100644 --- a/framework/Cache/lib/Horde/Cache/File.php +++ b/framework/Cache/lib/Horde/Cache/File.php @@ -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; } /** diff --git a/framework/Cache/lib/Horde/Cache/Memcache.php b/framework/Cache/lib/Horde/Cache/Memcache.php index 364c8c160..ac199e5b6 100644 --- a/framework/Cache/lib/Horde/Cache/Memcache.php +++ b/framework/Cache/lib/Horde/Cache/Memcache.php @@ -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); + } } /** diff --git a/framework/Cache/lib/Horde/Cache/Mock.php b/framework/Cache/lib/Horde/Cache/Mock.php index 55ee5e95b..48fe8fa8e 100644 --- a/framework/Cache/lib/Horde/Cache/Mock.php +++ b/framework/Cache/lib/Horde/Cache/Mock.php @@ -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) { diff --git a/framework/Cache/lib/Horde/Cache/Null.php b/framework/Cache/lib/Horde/Cache/Null.php index 06028fe65..c8f7589d7 100644 --- a/framework/Cache/lib/Horde/Cache/Null.php +++ b/framework/Cache/lib/Horde/Cache/Null.php @@ -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; } /** diff --git a/framework/Cache/lib/Horde/Cache/Sql.php b/framework/Cache/lib/Horde/Cache/Sql.php index d651e01a4..61c69f503 100644 --- a/framework/Cache/lib/Horde/Cache/Sql.php +++ b/framework/Cache/lib/Horde/Cache/Sql.php @@ -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) {} } /** diff --git a/framework/Cache/lib/Horde/Cache/Stack.php b/framework/Cache/lib/Horde/Cache/Stack.php index 8cdc74b3f..434be713b 100644 --- a/framework/Cache/lib/Horde/Cache/Stack.php +++ b/framework/Cache/lib/Horde/Cache/Stack.php @@ -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; } /** diff --git a/framework/Cache/lib/Horde/Cache/Xcache.php b/framework/Cache/lib/Horde/Cache/Xcache.php index 1574845a5..60fdca3b1 100644 --- a/framework/Cache/lib/Horde/Cache/Xcache.php +++ b/framework/Cache/lib/Horde/Cache/Xcache.php @@ -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); } /** diff --git a/framework/Cache/package.xml b/framework/Cache/package.xml index a0561cb20..6952f37d4 100644 --- a/framework/Cache/package.xml +++ b/framework/Cache/package.xml @@ -33,7 +33,8 @@ Performance Suite's content cache), memcached, or an SQL table. beta LGPL - * Added Horde_Cache_Exception::. + * Horde_Cache_Base::set() no longer returns a boolean result. + * Added Horde_Cache_Exception::. * Removed dependency on Horde Core. * Initial Horde 4 package. diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php index 33c70116e..252a9f2d9 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php @@ -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']); } /** diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php index 89dd80e1e..71b4319da 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php @@ -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; } /** diff --git a/framework/Template/lib/Horde/Template.php b/framework/Template/lib/Horde/Template.php index 90ce4d182..abb616901 100644 --- a/framework/Template/lib/Horde/Template.php +++ b/framework/Template/lib/Horde/Template.php @@ -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'); + } } } -- 2.11.0