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));
}
*/
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);
}
}