From ee2f36def7f90274040b3c391222e91f534d359d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sat, 30 Jan 2010 17:42:11 -0700 Subject: [PATCH] All code should now use injector to get a Horde_Cache instance --- agora/lib/Messages.php | 3 +- agora/rss/index.php | 3 +- agora/rss/messages.php | 5 +-- agora/rss/threads.php | 5 +-- ansel/lib/Application.php | 2 +- chora/lib/Application.php | 8 ++-- folks/lib/Block/my_comments.php | 3 +- folks/lib/Friends.php | 3 +- folks/lib/base.php | 3 +- framework/Cache/lib/Horde/Cache.php | 44 ---------------------- framework/Cache/lib/Horde/Cache/Sql.php | 13 +++---- framework/Core/lib/Horde.php | 4 +- framework/Core/lib/Horde/Core/Binder/Cache.php | 33 +++++++++------- framework/Group/Group/contactlists.php | 3 +- .../Imap_Client/lib/Horde/Imap/Client/Cache.php | 19 ++++------ .../Kolab_Storage/lib/Horde/Kolab/Storage.php | 5 +-- .../lib/Horde/Kolab/Storage/Cache.php | 2 +- framework/Perms/lib/Horde/Perms/Datatree.php | 3 +- .../lib/Horde/Perms/Permission/DataTreeObject.php | 2 +- .../Perms/lib/Horde/Perms/Permission/SqlObject.php | 2 +- framework/Perms/lib/Horde/Perms/Sql.php | 2 +- framework/Template/lib/Horde/Template.php | 2 +- framework/Ui/lib/Horde/Ui/VarRenderer/Html.php | 4 +- gollem/lib/Gollem.php | 4 +- horde/lib/Block/feed/reader.php | 3 +- horde/lib/Block/twitter_timeline.php | 3 +- horde/services/cache.php | 2 +- horde/services/cacheview.php | 2 +- horde/services/twitter.php | 5 +-- hylax/img.php | 2 +- imp/lib/Crypt/Pgp.php | 2 +- imp/lib/Folder.php | 4 +- imp/lib/IMP.php | 15 -------- imp/lib/Imap.php | 6 +-- imp/lib/Imap/Tree.php | 8 ++-- news/lib/Block/my_comments.php | 3 +- news/lib/base.php | 3 +- operator/lib/Application.php | 2 +- turba/lib/Driver/Imsp.php | 2 +- 39 files changed, 77 insertions(+), 162 deletions(-) diff --git a/agora/lib/Messages.php b/agora/lib/Messages.php index 0f23255e3..79f7211ca 100644 --- a/agora/lib/Messages.php +++ b/agora/lib/Messages.php @@ -89,8 +89,7 @@ class Agora_Messages { $this->_connect(); /* Initialize the Cache object. */ - $this->_cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $this->_cache = $GLOBALS['injector']->getInstance('Horde_Cache'); } /** diff --git a/agora/rss/index.php b/agora/rss/index.php index 12e47fd11..596b74f08 100644 --- a/agora/rss/index.php +++ b/agora/rss/index.php @@ -16,8 +16,7 @@ $scope = Horde_Util::getGet('scope', 'agora'); $cache_key = 'agora_rss_' . $scope; /* Initialize the Cache object. */ -$cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); +$cache = $injector->getInstance('Horde_Cache') $rss = $cache->get($cache_key, $conf['cache']['default_lifetime']); if (!$rss) { diff --git a/agora/rss/messages.php b/agora/rss/messages.php index bd31ebdf5..c7932d411 100644 --- a/agora/rss/messages.php +++ b/agora/rss/messages.php @@ -16,13 +16,10 @@ list($forum_id, $message_id, $scope) = Agora::getAgoraId(); $cache_key = 'agora_rss_' . $scope . '_' . $forum_id . '_' . $message_id; /* Initialize the Cache object. */ -$cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); - +$cache = $injector->getInstance('Horde_Cache'); $rss = $cache->get($cache_key, $conf['cache']['default_lifetime']); if (!$rss) { - $messages = Agora_Messages::singleton($scope, $forum_id); $message = $messages->getMessage($message_id); if ($message instanceof PEAR_Error) { diff --git a/agora/rss/threads.php b/agora/rss/threads.php index bfc348448..ebd99a709 100644 --- a/agora/rss/threads.php +++ b/agora/rss/threads.php @@ -34,13 +34,10 @@ if ($scope != 'agora') { $cache_key = 'agora_rss_' . $scope . '_' . $forum_id; /* Initialize the Cache object. */ -$cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); - +$cache = $injector->getInstance('Horde_Cache'); $rss = $cache->get($cache_key, $conf['cache']['default_lifetime']); if (!$rss) { - // Get forum title $threads = Agora_Messages::singleton($scope, $forum_id); if ($threads instanceof PEAR_Error) { diff --git a/ansel/lib/Application.php b/ansel/lib/Application.php index b8de79704..064cf3348 100644 --- a/ansel/lib/Application.php +++ b/ansel/lib/Application.php @@ -59,7 +59,7 @@ class Ansel_Application extends Horde_Registry_Application { // Create a cache object if we need it. if ($GLOBALS['conf']['ansel_cache']['usecache']) { - $GLOBALS['cache'] = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $GLOBALS['cache'] = $GLOBALS['injector']->getInstance('Horde_Cache'); } // Create db, share, and vfs instances. diff --git a/chora/lib/Application.php b/chora/lib/Application.php index 0be528c64..3899634fc 100644 --- a/chora/lib/Application.php +++ b/chora/lib/Application.php @@ -123,11 +123,9 @@ class Chora_Application extends Horde_Registry_Application $sourceroot = $acts['rt']; // Cache. - if (empty($conf['caching'])) { - $cache = null; - } else { - $cache = Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); - } + $cache = empty($conf['caching']) + ? null + : $GLOBALS['injector']->getInstance('Horde_Cache'); $conf['paths']['temp'] = Horde::getTempDir(); diff --git a/folks/lib/Block/my_comments.php b/folks/lib/Block/my_comments.php index 581cbfa40..b00ff9bbd 100644 --- a/folks/lib/Block/my_comments.php +++ b/folks/lib/Block/my_comments.php @@ -40,8 +40,7 @@ class Horde_Block_folks_my_comments extends Horde_Block { return ''; } - $GLOBALS['cache'] = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $GLOBALS['cache'] = $GLOBALS['injector']->getInstance('Horde_Cache'); $cache_key = 'folks_myscommetns_' . $this->_params['limit']; $threads = $GLOBALS['cache']->get($cache_key, $GLOBALS['conf']['cache']['default_lifetime']); diff --git a/folks/lib/Friends.php b/folks/lib/Friends.php index a857a2bec..ad0e3a920 100644 --- a/folks/lib/Friends.php +++ b/folks/lib/Friends.php @@ -114,8 +114,7 @@ class Folks_Friends { { $this->_user = empty($params['user']) ? Horde_Auth::getAuth() : $params['user']; - $this->_cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $this->_cache = $GLOBALS['injector']->getInstance('Horde_Cache'); } /** diff --git a/folks/lib/base.php b/folks/lib/base.php index ba1cbe363..ae9f7d9c5 100644 --- a/folks/lib/base.php +++ b/folks/lib/base.php @@ -38,8 +38,7 @@ if (!defined('FOLKS_BASE')) { $GLOBALS['folks_driver'] = Folks_Driver::factory(); // Cache -$GLOBALS['cache'] = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); +$GLOBALS['cache'] = $injector->getInstance('Horde_Cache'); // Update user online status $GLOBALS['folks_driver']->updateOnlineStatus(); diff --git a/framework/Cache/lib/Horde/Cache.php b/framework/Cache/lib/Horde/Cache.php index 2aeb30123..ea6bdf9ce 100644 --- a/framework/Cache/lib/Horde/Cache.php +++ b/framework/Cache/lib/Horde/Cache.php @@ -16,13 +16,6 @@ class Horde_Cache { /** - * Singleton instances. - * - * @var array - */ - static protected $_instances = array(); - - /** * Attempts to return a concrete Horde_Cache instance based on $driver. * * @param mixed $driver The type of concrete Horde_Cache subclass to @@ -48,10 +41,6 @@ class Horde_Cache return new Horde_Cache_Null($params); } - if ($driver == 'memcache') { - $params['memcache'] = $GLOBALS['injector']->getInstance('Horde_Memcache'); - } - $class = (empty($app) ? 'Horde' : $app) . '_Cache_' . ucfirst($driver); if (class_exists($class)) { return new $class($params); @@ -60,37 +49,4 @@ class Horde_Cache throw new Horde_Exception('Class definition of ' . $class . ' not found.'); } - /** - * Attempts to return a reference to a concrete Horde_Cache instance - * based on $driver. It will only create a new instance if no - * Horde_Cache instance with the same parameters currently exists. - * - * This should be used if multiple cache backends (and, thus, - * multiple Horde_Cache instances) are required. - * - * This method must be invoked as: - * $var = Horde_Cache::singleton() - * - * @param mixed $driver The type of concrete Horde_Cache subclass to - * return. If $driver is an array, then we will look - * in $driver[0]/lib/Cache/ for the subclass - * implementation named $driver[1].php. - * @param array $params A hash containing any additional configuration or - * connection parameters a subclass might need. - * - * @return Horde_Cache The concrete Horde_Cache reference. - * @throws Horde_Exception - */ - static public function singleton($driver, $params = array()) - { - ksort($params); - $signature = hash('md5', serialize(array($driver, $params))); - - if (!isset(self::$_instances[$signature])) { - self::$_instances[$signature] = self::factory($driver, $params); - } - - return self::$_instances[$signature]; - } - } diff --git a/framework/Cache/lib/Horde/Cache/Sql.php b/framework/Cache/lib/Horde/Cache/Sql.php index 87759f411..09efe860b 100644 --- a/framework/Cache/lib/Horde/Cache/Sql.php +++ b/framework/Cache/lib/Horde/Cache/Sql.php @@ -16,12 +16,10 @@ * 'port' The port on which to connect to the database. * * Optional parameters:
- *   'table'               The name of the cache table in 'database'.
- *                         Defaults to 'horde_cache'.
- *   'use_memorycache'     Use a Horde_Cache:: memory caching driver to cache
- *                         the data (to avoid DB accesses).  Either empty or
- *                         'none' if not needed, or else the name of a valid
- *                         Horde_Cache:: driver.
+ * 'table' The name of the cache table in 'database'. + * Defaults to 'horde_cache'. + * 'use_memorycache' Use this Horde_Cache:: memory caching object to cache + * the data (to avoid DB accesses). * * Optional values when using separate reading and writing servers, for example * in replication settings:
@@ -104,9 +102,8 @@ class Horde_Cache_Sql extends Horde_Cache_Base
             $this->_params['table'] = 'horde_cache';
         }
 
-        /* Create the memory cache object, if configured. */
         if (!empty($this->_params['use_memorycache'])) {
-            $this->_mc = Horde_Cache::singleton($params['use_memorycache'], !empty($conf['cache'][$params['use_memorycache']]) ? $conf['cache'][$params['use_memorycache']] : array());
+            $this->_mc = $this->_params['use_memorycache'];
         }
 
         parent::__construct($this->_params);
diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php
index 31630801d..e74c9f736 100644
--- a/framework/Core/lib/Horde.php
+++ b/framework/Core/lib/Horde.php
@@ -338,7 +338,7 @@ HTML;
         }
 
         if ($driver == 'horde_cache') {
-            $cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], self::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver']));
+            $cache = $GLOBALS['injector']->getInstance('Horde_Cache');
             $cache_lifetime = empty($conf['cachejsparams']['lifetime'])
                 ? 0
                 : $conf['cachejsparams']['lifetime'];
@@ -1716,7 +1716,7 @@ HTML;
                 break;
 
             case 'horde_cache':
-                $cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], self::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver']));
+                $cache = $GLOBALS['injector']->getInstance('Horde_Cache');
 
                 // Do lifetime checking here, not on cache display page.
                 $exists = $cache->exists($sig, empty($GLOBALS['conf']['cachecssparams']['lifetime']) ? 0 : $GLOBALS['conf']['cachecssparams']['lifetime']);
diff --git a/framework/Core/lib/Horde/Core/Binder/Cache.php b/framework/Core/lib/Horde/Core/Binder/Cache.php
index 237035595..f704c2a54 100644
--- a/framework/Core/lib/Horde/Core/Binder/Cache.php
+++ b/framework/Core/lib/Horde/Core/Binder/Cache.php
@@ -3,30 +3,35 @@ class Horde_Core_Binder_Cache implements Horde_Injector_Binder
 {
     public function create(Horde_Injector $injector)
     {
-        $driver = $GLOBALS['conf']['cache']['driver'];
+        return $this->_getCacheInstance($GLOBALS['conf']['cache']['driver'], $injector);
+    }
+
+    protected function _getCacheInstance($driver, $injector)
+    {
         $params = Horde::getDriverConfig('cache', $driver);
 
         if (is_array($driver)) {
             list($app, $driver_name) = $driver;
-            $driver = basename($driver_name);
         } else {
-            $driver = basename($driver);
+            $app = 'Horde';
+            $driver_name = basename($driver);
         }
 
-        if (empty($driver) || ($driver == 'none')) {
-            return new Horde_Cache_Null($params);
-        }
-
-        if ($driver == 'memcache') {
-            $params['memcache'] = $injector->getInstance('Horde_Memcache');
-        }
+        if (strtolower($app) == 'horde') {
+            switch (strtolower($driver)) {
+            case 'memcache':
+                $params['memcache'] = $injector->getInstance('Horde_Memcache');
+                break;
 
-        $class = (empty($app) ? 'Horde' : $app) . '_Cache_' . ucfirst($driver);
-        if (class_exists($class)) {
-            return new $class($params);
+            case 'sql':
+                if (!empty($params['use_memorycache'])) {
+                    $params['use_memorycache'] = $this->_getCacheInstance($params['use_memorycache'], $injector);
+                }
+                break;
+            }
         }
 
-        throw new Horde_Exception('Class definition of ' . $class . ' not found.');
+        return Horde_Cache::factory($driver, $params);
     }
 
     public function equals(Horde_Injector_Binder $binder)
diff --git a/framework/Group/Group/contactlists.php b/framework/Group/Group/contactlists.php
index cdd2400d8..6a33dfd84 100644
--- a/framework/Group/Group/contactlists.php
+++ b/framework/Group/Group/contactlists.php
@@ -58,8 +58,7 @@ class Group_contactlists extends Group {
             }
         }
 
-        $this->_cache = &Horde_Cache::singleton(
-            $GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver']));
+        $this->_cache = $GLOBALS['injector']->getInstance('Horde_Cache');
     }
 
     /**
diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Cache.php b/framework/Imap_Client/lib/Horde/Imap/Client/Cache.php
index 39e45845b..da9c3b965 100644
--- a/framework/Imap_Client/lib/Horde/Imap/Client/Cache.php
+++ b/framework/Imap_Client/lib/Horde/Imap/Client/Cache.php
@@ -5,10 +5,10 @@
  *
  * Requires Horde_Cache and Horde_Serialize packages.
  *
+ * 
  * REQUIRED Parameters:
  * ====================
- * 'driver' - (string) The Horde_Cache driver to use.
- * 'driver_params' - (string) The params to pass to the Horde_Cache driver.
+ * 'cacheob' - (Horde_Cache) The cache object to use.
  * 'hostspec' - (string) The IMAP hostspec.
  * 'port' - (string) The IMAP port.
  * 'username' - (string) The IMAP username.
@@ -25,6 +25,7 @@
  *              DEFAULT: 1 week (604800 secs)
  * 'slicesize' - (integer) The slicesize to use.
  *               DEFAULT: 50
+ * 
* * Copyright 2005-2010 The Horde Project (http://www.horde.org/) * @@ -111,21 +112,15 @@ class Horde_Imap_Client_Cache * @param array $params The configuration parameters. * * @throws Horde_Imap_Client_Exception + * @throws InvalidArgumentException */ public function __construct($params = array()) { - if (empty($params['driver']) || - empty($params['driver_params']) || + if (empty($params['cacheob']) || empty($params['hostspec']) || empty($params['port']) || empty($params['username'])) { - throw new Horde_Imap_Client_Exception('Missing required parameters to Horde_Imap_Client_Cache.'); - } - - /* Initialize the Cache object. */ - $this->_cache = Horde_Cache::singleton($params['driver'], $params['driver_params']); - if (is_a($this->_cache, 'PEAR_Error')) { - throw new Horde_Imap_Client_Exception($this->_cache->getMessage()); + throw new InvalidArgumentException('Missing required parameters to Horde_Imap_Client_Cache.'); } $compress = null; @@ -149,6 +144,8 @@ class Horde_Imap_Client_Cache } } + $this->_cache = $params['cacheob']; + $this->_params = array( 'compress' => $compress, 'debug' => empty($params['debug']) ? false : $params['debug'], diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php index a1cb93c44..7fe5bc4b9 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage.php @@ -149,13 +149,12 @@ class Horde_Kolab_Storage if (!empty($GLOBALS['conf']['kolab']['storage']['cache']['folders'])) { $signature = hash('md5', serialize(array($driver, $params))) . '|list'; - $this->_cache = &Horde_Cache::singleton($GLOBALS['conf']['kolab']['storage']['cache']['folders']['driver'], - $GLOBALS['conf']['kolab']['storage']['cache']['folders']['params']); + $this->_cache = $GLOBALS['injector']->getInstance('Horde_Cache'); $data = $this->_cache->get($signature, $GLOBALS['conf']['kolab']['storage']['cache']['folders']['lifetime']); if ($data) { - $list = @unserialize($data); + $list = @unserialize($data);; if ($list instanceOf Horde_Kolab_Storage) { register_shutdown_function(array($list, 'shutdown')); return $list; diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php index 6ef0e5f2d..8b65e8c5f 100644 --- a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php +++ b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache.php @@ -152,7 +152,7 @@ class Horde_Kolab_Storage_Cache $params = $GLOBALS['conf']['kolab']['storage']['cache']['data']['params']; } } - $this->horde_cache = Horde_Cache::singleton($driver, $params); + $this->horde_cache = $GLOBALS['injector']->getInstance('Horde_Cache'); } /** diff --git a/framework/Perms/lib/Horde/Perms/Datatree.php b/framework/Perms/lib/Horde/Perms/Datatree.php index 397cd0db1..303f7ba22 100644 --- a/framework/Perms/lib/Horde/Perms/Datatree.php +++ b/framework/Perms/lib/Horde/Perms/Datatree.php @@ -61,8 +61,7 @@ class Horde_Perms_Datatree extends Horde_Perms array_merge(Horde::getDriverConfig('datatree', $driver), array('group' => 'horde.perms'))); - $this->_cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $this->_cache = $GLOBALS['injector']->getInstance('Horde_Cache'); parent::__construct(); } diff --git a/framework/Perms/lib/Horde/Perms/Permission/DataTreeObject.php b/framework/Perms/lib/Horde/Perms/Permission/DataTreeObject.php index a81cd6c2f..7517a039f 100644 --- a/framework/Perms/lib/Horde/Perms/Permission/DataTreeObject.php +++ b/framework/Perms/lib/Horde/Perms/Permission/DataTreeObject.php @@ -554,7 +554,7 @@ class Horde_Perms_Permission_DataTreeObject extends DataTreeObject parent::save(); - $cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); $cache->expire('perm_' . $name); $cache->expire('perm_exists_' . $name); } diff --git a/framework/Perms/lib/Horde/Perms/Permission/SqlObject.php b/framework/Perms/lib/Horde/Perms/Permission/SqlObject.php index 7e5e7bb1e..7fb6f04c3 100644 --- a/framework/Perms/lib/Horde/Perms/Permission/SqlObject.php +++ b/framework/Perms/lib/Horde/Perms/Permission/SqlObject.php @@ -77,7 +77,7 @@ class Horde_Perms_Permission_SqlObject extends Horde_Perms_Permission throw new Horde_Perms_Exception($result); } - $cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); $cache->expire('perm_sql_' . $name); $cache->expire('perm_sql_exists_' . $name); } diff --git a/framework/Perms/lib/Horde/Perms/Sql.php b/framework/Perms/lib/Horde/Perms/Sql.php index 4b96887ed..c843f3068 100644 --- a/framework/Perms/lib/Horde/Perms/Sql.php +++ b/framework/Perms/lib/Horde/Perms/Sql.php @@ -62,7 +62,7 @@ class Horde_Perms_Sql extends Horde_Perms */ public function __construct() { - $this->_cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $this->_cache = $GLOBALS['injector']->getInstance('Horde_Cache'); } /** diff --git a/framework/Template/lib/Horde/Template.php b/framework/Template/lib/Horde/Template.php index 876ea2d39..85c34d1fd 100644 --- a/framework/Template/lib/Horde/Template.php +++ b/framework/Template/lib/Horde/Template.php @@ -109,7 +109,7 @@ class Horde_Template } try { - $this->_cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $this->_cache = $GLOBALS['injector']->getInstance('Horde_Cache'); } catch (Horde_Exception $e) {} } diff --git a/framework/Ui/lib/Horde/Ui/VarRenderer/Html.php b/framework/Ui/lib/Horde/Ui/VarRenderer/Html.php index ddbccde70..7cf2cb498 100644 --- a/framework/Ui/lib/Horde/Ui/VarRenderer/Html.php +++ b/framework/Ui/lib/Horde/Ui/VarRenderer/Html.php @@ -1428,8 +1428,8 @@ EOT; } $cid = md5($var->type->getText()); - $cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); + $cache->set($cid, serialize(array('data' => $captcha->getCAPTCHAAsJPEG(), 'ctype' => 'image/jpeg'))); diff --git a/gollem/lib/Gollem.php b/gollem/lib/Gollem.php index 0440eb887..3a62c4687 100644 --- a/gollem/lib/Gollem.php +++ b/gollem/lib/Gollem.php @@ -217,7 +217,7 @@ class Gollem ($conf['cache']['driver'] != 'none')) { $key = self::_getCacheID($dir); - $cache = Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); + $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); $res = $cache->get($key, $conf['foldercache']['lifetime']); if ($res !== false) { $res = Horde_Serialize::unserialize($res, Horde_Serialize::BASIC); @@ -268,7 +268,7 @@ class Gollem if (!empty($conf['foldercache']['use_cache']) && !empty($conf['cache']['driver']) && ($conf['cache']['driver'] != 'none')) { - $cache = Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); + $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); $cache->expire(self::_getCacheID($dir)); } } diff --git a/horde/lib/Block/feed/reader.php b/horde/lib/Block/feed/reader.php index 5a9883d1d..b6d673624 100644 --- a/horde/lib/Block/feed/reader.php +++ b/horde/lib/Block/feed/reader.php @@ -13,8 +13,7 @@ class Horde_Block_Horde_feed_reader { $key = md5($uri); - $GLOBALS['cache'] = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $GLOBALS['cache'] = $GLOBALS['injector']->getInstance('Horde_Cache'); $feed = $GLOBALS['cache']->get($key, $interval); if (!empty($feed)) { diff --git a/horde/lib/Block/twitter_timeline.php b/horde/lib/Block/twitter_timeline.php index 8037b5b07..2bd4ccae9 100644 --- a/horde/lib/Block/twitter_timeline.php +++ b/horde/lib/Block/twitter_timeline.php @@ -265,8 +265,7 @@ EOF; return $this->_twitter; } - $cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); if (!empty($GLOBALS['conf']['twitter']['key']) && !empty($GLOBALS['conf']['twitter']['secret'])) { diff --git a/horde/services/cache.php b/horde/services/cache.php index 615cf4075..39dd9cae1 100644 --- a/horde/services/cache.php +++ b/horde/services/cache.php @@ -64,7 +64,7 @@ case 'js': } try { - $cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $cache = $injector->getInstance('Horde_Cache'); } catch (Horde_Exception $e) { exit; } diff --git a/horde/services/cacheview.php b/horde/services/cacheview.php index 82278cb36..cb5008fe5 100644 --- a/horde/services/cacheview.php +++ b/horde/services/cacheview.php @@ -16,7 +16,7 @@ if (empty($cid)) { exit; } -$cache = Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); +$cache = $injector->getInstance('Horde_Cache'); $cdata = @unserialize($cache->get($cid, $conf['cache']['default_lifetime'])); if (!$cdata) { exit; diff --git a/horde/services/twitter.php b/horde/services/twitter.php index b7d27a5ab..805149dbe 100644 --- a/horde/services/twitter.php +++ b/horde/services/twitter.php @@ -18,9 +18,8 @@ if (empty($GLOBALS['conf']['twitter']['enabled'])) { exit; } -/* Create a cahce object for the twitter client */ -$cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); +/* Create a cache object for the twitter client */ +$cache = $injector->getInstance('Horde_Cache'); /* Using OAuth or Http Basic? */ if (!empty($GLOBALS['conf']['twitter']['key']) && !empty($GLOBALS['conf']['twitter']['secret'])) { diff --git a/hylax/img.php b/hylax/img.php index 0f91bacc1..b7e3e4dde 100644 --- a/hylax/img.php +++ b/hylax/img.php @@ -14,7 +14,7 @@ $page = Horde_Util::getFormData('page'); $preview = Horde_Util::getFormData('preview'); /* Set up the cache object. */ -$cache = Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); +$cache = $injector->getInstance('Horde_Cache'); /* Call the get the image data using cache. */ $id = $fax_id . '_' . $page . ($preview ? '_p' : ''); diff --git a/imp/lib/Crypt/Pgp.php b/imp/lib/Crypt/Pgp.php index 1d7a4b932..b3a8164fd 100644 --- a/imp/lib/Crypt/Pgp.php +++ b/imp/lib/Crypt/Pgp.php @@ -171,7 +171,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp /* If there is a cache driver configured, try to get the public key * from the cache. */ - if (empty($options['nocache']) && ($cache = IMP::getCache())) { + if (empty($options['nocache']) && ($cache = $GLOBALS['injector']->getInstance('Horde_Cache'))) { $result = $cache->get("PGPpublicKey_" . $address . $keyid, 3600); if ($result) { Horde::logMessage('PGPpublicKey: ' . serialize($result), __FILE__, __LINE__, PEAR_LOG_DEBUG); diff --git a/imp/lib/Folder.php b/imp/lib/Folder.php index cf31ffc6f..21571cffc 100644 --- a/imp/lib/Folder.php +++ b/imp/lib/Folder.php @@ -105,7 +105,7 @@ class IMP_Folder obtain it. */ $cache = null; if (is_null($this->_listCache)) { - if (!is_null($this->_cacheid) && ($cache = IMP::getCache())) { + if (!is_null($this->_cacheid) && ($cache = $GLOBALS['injector']->getInstance('Horde_Cache'))) { $ret = $cache->get($this->_cacheid, 3600); if (!empty($ret)) { $this->_listCache = unserialize($ret); @@ -159,7 +159,7 @@ class IMP_Folder */ public function clearFlistCache() { - if (!is_null($this->_cacheid) && ($cache = IMP::getCache())) { + if (!is_null($this->_cacheid) && ($cache = $GLOBALS['injector']->getInstance('Horde_Cache'))) { $cache->expire($this->_cacheid); } $this->_listCache = array(); diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 4e2a8667c..8edffc5a7 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -1049,21 +1049,6 @@ class IMP } /** - * Returns a Horde_Cache object (if configured) and handles any errors - * associated with creating the object. - * - * @return mixed A Horde_Cache object or null. - * @throws Horde_Exception - */ - public static function getCache() - { - $cache = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); - return ($cache instanceof Horde_Cache_Null) - ? null - : $cache; - } - - /** * Generate the JS code necessary to open a passphrase dialog. Adds the * necessary JS files to open the dialog. * diff --git a/imp/lib/Imap.php b/imp/lib/Imap.php index a881cdbd5..abbaf0399 100644 --- a/imp/lib/Imap.php +++ b/imp/lib/Imap.php @@ -225,8 +225,7 @@ class IMP_Imap */ public function loadCacheConfig($config) { - $driver = $GLOBALS['conf']['cache']['driver']; - if ($driver == 'none') { + if (!($ob = $GLOBALS['injector']->getInstance('Horde_Cache'))) { return array(); } @@ -239,9 +238,8 @@ class IMP_Imap } return array( + 'cacheob' => $ob, 'compress' => empty($config['compress']) ? false : $config['compress'], - 'driver' => $driver, - 'driver_params' => Horde::getDriverConfig('cache', $driver), 'lifetime' => empty($config['lifetime']) ? false : $config['lifetime'], 'slicesize' => empty($config['slicesize']) ? false : $config['slicesize'], ); diff --git a/imp/lib/Imap/Tree.php b/imp/lib/Imap/Tree.php index 58a5ee446..d1bf571a9 100644 --- a/imp/lib/Imap/Tree.php +++ b/imp/lib/Imap/Tree.php @@ -216,8 +216,7 @@ class IMP_Imap_Tree { if (!isset(self::$_instance)) { if (!empty($_SESSION['imp']['cache']['tree'])) { - $imp_cache = IMP::getCache(); - self::$_instance = @unserialize($imp_cache->get($_SESSION['imp']['cache']['tree'], 86400)); + self::$_instance = @unserialize($GLOBALS['injector']->getInstance('Horde_Cache')->get($_SESSION['imp']['cache']['tree'], 86400)); } if (empty(self::$_instance)) { @@ -242,7 +241,7 @@ class IMP_Imap_Tree : $ns; } - if ($imp_cache = IMP::getCache()) { + if ($imp_cache = $GLOBALS['injector']->getInstance('Horde_Cache')) { $_SESSION['imp']['cache']['tree'] = uniqid(mt_rand() . Horde_Auth::getAuth()); } @@ -276,8 +275,7 @@ class IMP_Imap_Tree * has changed. */ if (!empty($this->_changed) && isset($_SESSION['imp']['cache']['tree'])) { - $imp_cache = IMP::getCache(); - $imp_cache->set($_SESSION['imp']['cache']['tree'], serialize($this), 86400); + $GLOBALS['injector']->getInstance('Horde_Cache')->set($_SESSION['imp']['cache']['tree'], serialize($this), 86400); } } diff --git a/news/lib/Block/my_comments.php b/news/lib/Block/my_comments.php index 2f5e81ae0..2feba13b8 100644 --- a/news/lib/Block/my_comments.php +++ b/news/lib/Block/my_comments.php @@ -40,8 +40,7 @@ class Horde_Block_news_my_comments extends Horde_Block { return ''; } - $GLOBALS['cache'] = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $GLOBALS['cache'] = $GLOBALS['injector']->getInstance('Horde_Cache'); $cache_key = 'news_myscommetns_' . $this->_params['limit']; $threads = $GLOBALS['cache']->get($cache_key, $GLOBALS['conf']['cache']['default_lifetime']); diff --git a/news/lib/base.php b/news/lib/base.php index b0ce4f485..e1b10f495 100644 --- a/news/lib/base.php +++ b/news/lib/base.php @@ -42,8 +42,7 @@ if (!defined('NEWS_BASE')) { } // Cache -$GLOBALS['cache'] = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], - Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); +$GLOBALS['cache'] = $injector->getInstance('Horde_Cache'); // Set up News drivers. $GLOBALS['news'] = News_Driver::factory(); diff --git a/operator/lib/Application.php b/operator/lib/Application.php index 86d512c5e..c965463d7 100644 --- a/operator/lib/Application.php +++ b/operator/lib/Application.php @@ -64,7 +64,7 @@ class Operator_Application extends Horde_Registry_Application $this->driver = Operator_Driver::factory(); // Caching system for storing DB results - $GLOBALS['cache'] = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + $GLOBALS['cache'] = $GLOBALS['injector']->getInstance('Horde_Cache'); } /** diff --git a/turba/lib/Driver/Imsp.php b/turba/lib/Driver/Imsp.php index b24c52140..4bfc8e1f3 100644 --- a/turba/lib/Driver/Imsp.php +++ b/turba/lib/Driver/Imsp.php @@ -447,7 +447,7 @@ class Turba_Driver_Imsp extends Turba_Driver $searchop = $criteria['op']; $hasName = false; $this->_noGroups = false; - $cache = &Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); + $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); $key = implode(".", array_merge($criteria, array($this->_bookName))); /* Now make sure we aren't searching on a dynamically created -- 2.11.0