summaryrefslogtreecommitdiff
path: root/program/include/rcmail.php
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2011-05-18 11:48:47 +0000
committeralecpl <alec@alec.pl>2011-05-18 11:48:47 +0000
commit5cf5ee66c1fd3e86f009124aee58df26780ce311 (patch)
tree4fdb2b6b43bad4215672c3e97643c71f6e3a3bee /program/include/rcmail.php
parent76d4019a355019f2cc3465bd36e3475f80c3d745 (diff)
- Added general rcube_cache class with memcache support
- Improved caching performance by skipping writes of unchanged data - Option enable_caching replaced by imap_cache and messages_cache options
Diffstat (limited to 'program/include/rcmail.php')
-rw-r--r--program/include/rcmail.php40
1 files changed, 36 insertions, 4 deletions
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index eb08c81dc..e2ce1bfbb 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -122,6 +122,7 @@ class rcmail
private $texts;
private $address_books = array();
+ private $caches = array();
private $action_map = array();
@@ -352,6 +353,24 @@ class rcmail
/**
+ * Initialize and get cache object
+ *
+ * @param string $name Cache identifier
+ * @param string $type Cache type ('db' 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 @@ class rcmail
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 @@ class rcmail
$book->close();
}
+ foreach ($this->caches as $cache) {
+ if (is_object($cache))
+ $cache->close();
+ }
+
if (is_object($this->imap))
$this->imap->close();