IMP_Imap_Tree should always be cached.
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 3 Sep 2010 18:44:24 +0000 (12:44 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 3 Sep 2010 19:59:29 +0000 (13:59 -0600)
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

index f99701f..09eed79 100644 (file)
 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);
         }
     }