From 377edf85872fa6d212b51b04781ceb6570416db9 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 3 Sep 2010 12:44:24 -0600 Subject: [PATCH] IMP_Imap_Tree should always be cached. Since IMAP tree generation is so expensive/time-consuming, fallback to storing in the session even if no permanent cache backend is setup. --- imp/lib/Injector/Binder/Imaptree.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/imp/lib/Injector/Binder/Imaptree.php b/imp/lib/Injector/Binder/Imaptree.php index f99701fbd..09eed7990 100644 --- a/imp/lib/Injector/Binder/Imaptree.php +++ b/imp/lib/Injector/Binder/Imaptree.php @@ -15,19 +15,28 @@ class IMP_Injector_Binder_Imaptree implements Horde_Injector_Binder { /** + * Injector. + * + * @var Horde_Injector + */ + private $_injector; + + /** * If an IMP_Imap_Tree object is currently stored in the cache, re-create * that object. Else, create a new instance. */ public function create(Horde_Injector $injector) { - $cache = $injector->getInstance('Horde_Cache'); - $instance = null; + $this->_injector = $injector; if (empty($_SESSION['imp']['cache']['tree'])) { - if (!($cache instanceof Horde_Cache_Null)) { - $_SESSION['imp']['cache']['tree'] = strval(new Horde_Support_Randomid()); - } + $_SESSION['imp']['cache']['tree'] = strval(new Horde_Support_Randomid()); + $instance = null; } else { + /* Since IMAP tree generation is so expensive/time-consuming, + * fallback to storing in the session even if no permanent cache + * backend is setup. */ + $cache = $injector->getInstance('Horde_Cache_Factory')->getCache(array('session' => true)); $instance = @unserialize($cache->get($_SESSION['imp']['cache']['tree'], 86400)); } @@ -45,10 +54,10 @@ class IMP_Injector_Binder_Imaptree implements Horde_Injector_Binder */ public function shutdown($instance) { - /* Only need to store the object if using Horde_Cache and the tree - * has changed. */ - if ($instance->changed && isset($_SESSION['imp']['cache']['tree'])) { - $GLOBALS['injector']->getInstance('Horde_Cache')->set($_SESSION['imp']['cache']['tree'], serialize($instance), 86400); + /* Only need to store the object if the tree has changed. */ + if ($instance->changed) { + $cache = $this->_injector->getInstance('Horde_Cache_Factory')->getCache(array('session' => true)); + $cache->set($_SESSION['imp']['cache']['tree'], serialize($instance), 86400); } } -- 2.11.0