From: Michael M Slusarz Date: Thu, 20 Nov 2008 22:17:35 +0000 (-0700) Subject: Add IMP::getCacheOb(). X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5b219e35f9be7f222a32775cf9a69b09a3640ac1;p=horde.git Add IMP::getCacheOb(). --- diff --git a/imp/lib/Crypt/pgp.php b/imp/lib/Crypt/pgp.php index ae7ffeb5c..2ca26005d 100644 --- a/imp/lib/Crypt/pgp.php +++ b/imp/lib/Crypt/pgp.php @@ -162,24 +162,16 @@ class IMP_Horde_Crypt_pgp extends Horde_Crypt_pgp */ public function getPublicKey($address, $fingerprint = null, $server = true) { - $result = false; - /* If there is a cache driver configured, try to get the public key * from the cache. */ - if (!empty($GLOBALS['conf']['cache']['driver'])) { - $cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); - if (is_a($cache, 'PEAR_Error')) { - Horde::fatal($cache, __FILE__, __LINE__); - } else { - $result = $cache->get("PGPpublicKey_" . $address . $fingerprint, 3600); + if (($cache = &IMP::getCacheOb())) { + $result = $cache->get("PGPpublicKey_" . $address . $fingerprint, 3600); + if ($result) { + Horde::logMessage('PGPpublicKey: ' . serialize($result), __FILE__, __LINE__, PEAR_LOG_DEBUG); + return $result; } } - if ($result) { - Horde::logMessage('PGPpublicKey: ' . serialize($result), __FILE__, __LINE__, PEAR_LOG_DEBUG); - return $result; - } - /* Try retrieving by e-mail only first. */ $params = IMP_Compose::getAddressSearchParams(); $result = $GLOBALS['registry']->call('contacts/getField', array($address, self::PUBKEY_FIELD, $params['sources'], false, true)); diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 4a6a25eed..b8bfc3350 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -1467,8 +1467,8 @@ class IMP if (empty($cache_type) || $cache_type == 'none' || - ($cache_type == 'horde_cache' && - $conf['cache']['driver'] == 'none')) { + (($cache_type == 'horde_cache') && + !($cache = &self::getCacheOb()))) { Horde::includeScriptFiles(); return; } @@ -1511,7 +1511,6 @@ class IMP break; case 'horde_cache': - $cache = &Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); $exists = $cache->exists($sig, empty($conf['server']['cachejsparams']['lifetime']) ? 0 : $conf['server']['cachejsparams']['lifetime']); $js_url = IMP::getCacheURL('js', $sig); break; @@ -1622,8 +1621,8 @@ class IMP if (empty($cache_type) || $cache_type == 'none' || - ($cache_type == 'horde_cache' && - $conf['cache']['driver'] == 'none')) { + (($cache_type == 'horde_cache') && + !($cache = &self::getCacheOb()))) { $css_out = array_merge($css, $css_out); } else { $mtime = array(0); @@ -1645,7 +1644,6 @@ class IMP break; case 'horde_cache': - $cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); $exists = $cache->exists($sig, empty($GLOBALS['conf']['server']['cachecssparams']['lifetime']) ? 0 : $GLOBALS['conf']['server']['cachecssparams']['lifetime']); $css_url = IMP::getCacheURL('css', $sig); break; @@ -1818,4 +1816,26 @@ class IMP return $msglist; } + + /** + * Returns a Horde_Cache object (if configured) and handles any errors + * associated with creating the object. + * + * @return Horde_Cache A pointer to a Horde_Cache object. + */ + static public function &getCacheOb() + { + global $conf; + + if ($conf['cache']['driver'] == 'none') { + return false; + } + + $cache = &Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); + if (is_a($cache, 'PEAR_Error')) { + Horde::fatal($cache, __FILE__, __LINE__); + } + + return $cache; + } } diff --git a/imp/lib/Template.php b/imp/lib/Template.php index f47ce7d78..b7022126a 100644 --- a/imp/lib/Template.php +++ b/imp/lib/Template.php @@ -109,7 +109,8 @@ class IMP_Template { $this->_basepath = $basepath; } - $this->_cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + + $this->_cache = &IMP::getCacheOb(); } /** @@ -211,7 +212,7 @@ class IMP_Template { /* First, check for a cached compiled version. */ $cacheid = 'horde_template|' . filemtime($file) . '|' . $file . '|' . $this->getOption('gettext'); - if (!$force && is_null($this->_template) && isset($this->_cache)) { + if (!$force && is_null($this->_template) && $this->_cache) { $this->_template = $this->_cache->get($cacheid, 0); if ($this->_template === false) { $this->_template = null;