From 3253b296c21c54df228de39ff3e4775974df81d5 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Fri, 20 May 2011 05:17:27 -0400
Subject: [PATCH] - Clear properly mailboxes cache on folder subscription change

---
 program/include/rcmail.php |   38 +++++++++++++++++++++++++++++++++++---
 1 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index eb08c81..98f3c3e 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -122,6 +122,7 @@
 
   private $texts;
   private $address_books = array();
+  private $caches = array();
   private $action_map = array();
 
 
@@ -352,6 +353,24 @@
 
 
   /**
+   * Initialize and get cache object
+   *
+   * @param string $name Cache identifier
+   * @param string $type Cache type ('db', 'apc' or 'memcache')
+   *
+   * @return rcube_cache Cache object
+   */
+  public function get_cache($name, $type)
+  {
+    if (!isset($this->caches[$name])) {
+      $this->caches[$name] = new rcube_cache($type, $_SESSION['user_id'], $name.'.');
+    }
+
+    return $this->caches[$name];
+  }
+
+
+  /**
    * Return instance of the internal address book class
    *
    * @param string  Address book identifier
@@ -531,14 +550,22 @@
     if (is_object($this->imap))
       return;
 
-    $this->imap = new rcube_imap($this->db);
+    $this->imap = new rcube_imap();
     $this->imap->debug_level = $this->config->get('debug_level');
     $this->imap->skip_deleted = $this->config->get('skip_deleted');
 
     // enable caching of imap data
-    if ($this->config->get('enable_caching')) {
-      $this->imap->set_caching(true);
+    $imap_cache = $this->config->get('imap_cache');
+    $messages_cache = $this->config->get('messages_cache');
+    // for backward compatybility
+    if ($imap_cache === null && $messages_cache === null && $this->config->get('enable_caching')) {
+        $imap_cache     = 'db';
+        $messages_cache = true;
     }
+    if ($imap_cache)
+        $this->imap->set_caching($imap_cache);
+    if ($messages_cache)
+        $this->imap->set_messages_caching(true);
 
     // set pagesize from config
     $this->imap->set_pagesize($this->config->get('pagesize', 50));
@@ -1116,6 +1143,11 @@
         $book->close();
     }
 
+    foreach ($this->caches as $cache) {
+        if (is_object($cache))
+            $cache->close();
+    }
+
     if (is_object($this->imap))
       $this->imap->close();
 

--
Gitblit v1.9.1