From 7735dfd29644885f8398b523dea1b6a30ec043bd Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 28 Jan 2010 22:45:30 -0700 Subject: [PATCH] Add IMP_Imap::loadCacheConfig() --- imp/lib/Imap.php | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/imp/lib/Imap.php b/imp/lib/Imap.php index a36b945c7..6e9e865d1 100644 --- a/imp/lib/Imap.php +++ b/imp/lib/Imap.php @@ -191,17 +191,7 @@ class IMP_Imap /* Initialize caching. */ if (!empty($server['cache'])) { - $c = $server['cache']; - $driver = $GLOBALS['conf']['cache']['driver']; - if ($driver != 'none') { - $imap_config['cache'] = array( - 'compress' => empty($c['compress']) ? false : $c['compress'], - 'driver' => $driver, - 'driver_params' => Horde::getDriverConfig('cache', $driver), - 'lifetime' => empty($c['lifetime']) ? false : $c['lifetime'], - 'slicesize' => empty($c['slicesize']) ? false : $c['slicesize'], - ); - } + $imap_config['cache'] = $this->loadCacheConfig(is_array($server['cache']) ? $server['cache'] : array()); } try { @@ -219,6 +209,39 @@ class IMP_Imap } /** + * Prepare the config parameters necessary to use IMAP caching. + * + * @param mixed $config Either a list of cache config parameters, or a + * string containing the name of the driver with + * which to load the cache config from. + * + * @return array The configuration array. + */ + public function loadCacheConfig($config) + { + $driver = $GLOBALS['conf']['cache']['driver']; + if ($driver == 'none') { + return array(); + } + + if (is_string($config)) { + if ((($server = $this->loadServerConfig($config)) === false) || + empty($server['cache'])) { + return array(); + } + $config = $server['cache']; + } + + return array( + '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'], + ); + } + + /** * Alter some IMP settings once we load/create the global object. * * @param string $protocol The protocol used to connect. -- 2.11.0