$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');
}
/**
$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) {
$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) {
$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) {
{
// 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.
$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();
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']);
{
$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');
}
/**
$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();
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
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);
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];
- }
-
}
* 'port' The port on which to connect to the database.</pre>
*
* Optional parameters:<pre>
- * '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.</pre>
+ * '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).</pre>
*
* Optional values when using separate reading and writing servers, for example
* in replication settings:<pre>
$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);
}
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'];
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']);
{
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)
}
}
- $this->_cache = &Horde_Cache::singleton(
- $GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver']));
+ $this->_cache = $GLOBALS['injector']->getInstance('Horde_Cache');
}
/**
*
* Requires Horde_Cache and Horde_Serialize packages.
*
+ * <pre>
* 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.
* DEFAULT: 1 week (604800 secs)
* 'slicesize' - (integer) The slicesize to use.
* DEFAULT: 50
+ * </pre>
*
* Copyright 2005-2010 The Horde Project (http://www.horde.org/)
*
* @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;
}
}
+ $this->_cache = $params['cacheob'];
+
$this->_params = array(
'compress' => $compress,
'debug' => empty($params['debug']) ? false : $params['debug'],
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;
$params = $GLOBALS['conf']['kolab']['storage']['cache']['data']['params'];
}
}
- $this->horde_cache = Horde_Cache::singleton($driver, $params);
+ $this->horde_cache = $GLOBALS['injector']->getInstance('Horde_Cache');
}
/**
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();
}
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);
}
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);
}
*/
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');
}
/**
}
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) {}
}
}
$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')));
($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);
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));
}
}
$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)) {
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'])) {
}
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;
}
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;
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'])) {
$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' : '');
/* 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);
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);
*/
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();
}
/**
- * 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.
*
*/
public function loadCacheConfig($config)
{
- $driver = $GLOBALS['conf']['cache']['driver'];
- if ($driver == 'none') {
+ if (!($ob = $GLOBALS['injector']->getInstance('Horde_Cache'))) {
return array();
}
}
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'],
);
{
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)) {
: $ns;
}
- if ($imp_cache = IMP::getCache()) {
+ if ($imp_cache = $GLOBALS['injector']->getInstance('Horde_Cache')) {
$_SESSION['imp']['cache']['tree'] = uniqid(mt_rand() . Horde_Auth::getAuth());
}
* 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);
}
}
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']);
}
// 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();
$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');
}
/**
$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