diff options
author | alecpl <alec@alec.pl> | 2011-05-18 12:37:00 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2011-05-18 12:37:00 +0000 |
commit | 8edb3d9405c7d409bcabe38274cafbd5438575f6 (patch) | |
tree | 558f03ae5a2b5eb4e4fcc586cc2e83d18847c5b2 /program | |
parent | b5f836e4af705679e13506c4edfe67ca3039f004 (diff) |
- Add APC support in rcube_cache
Diffstat (limited to 'program')
-rw-r--r-- | program/include/rcmail.php | 2 | ||||
-rw-r--r-- | program/include/rcube_cache.php | 40 | ||||
-rw-r--r-- | program/include/rcube_imap.php | 2 |
3 files changed, 35 insertions, 9 deletions
diff --git a/program/include/rcmail.php b/program/include/rcmail.php index e2ce1bfbb..98f3c3e66 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -356,7 +356,7 @@ class rcmail * Initialize and get cache object * * @param string $name Cache identifier - * @param string $type Cache type ('db' or 'memcache') + * @param string $type Cache type ('db', 'apc' or 'memcache') * * @return rcube_cache Cache object */ diff --git a/program/include/rcube_cache.php b/program/include/rcube_cache.php index dda09885c..2fe5903b4 100644 --- a/program/include/rcube_cache.php +++ b/program/include/rcube_cache.php @@ -51,18 +51,23 @@ class rcube_cache /** * Object constructor. * - * @param string $type Engine type ('db' or 'memcache') + * @param string $type Engine type ('db' or 'memcache' or 'apc') * @param int $userid User identifier * @param string $prefix Key name prefix */ function __construct($type, $userid, $prefix='') { $rcmail = rcmail::get_instance(); + $type = strtolower($type); - if (strtolower($type) == 'memcache') { + if ($type == 'memcache') { $this->type = 'memcache'; $this->db = $rcmail->get_memcache(); } + else if ($type == 'apc') { + $this->type = 'apc'; + $this->db = function_exists('apc_exists'); // APC 3.1.4 required + } else { $this->type = 'db'; $this->db = $rcmail->get_dbh(); @@ -208,7 +213,17 @@ class rcube_cache } if ($this->type == 'memcache') { - $data = $this->db->get($this->mc_key($key)); + $data = $this->db->get($this->ckey($key)); + + if ($data) { + $this->cache_sums[$key] = md5($data); + $data = unserialize($data); + } + return $this->cache[$key] = $data; + } + + if ($this->type == 'apc') { + $data = apc_fetch($this->ckey($key)); if ($data) { $this->cache_sums[$key] = md5($data); @@ -263,13 +278,20 @@ class rcube_cache } if ($this->type == 'memcache') { - $key = $this->mc_key($key); + $key = $this->ckey($key); $result = $this->db->replace($key, $data, MEMCACHE_COMPRESSED); if (!$result) $result = $this->db->set($key, $data, MEMCACHE_COMPRESSED); return $result; } + if ($this->type == 'apc') { + $key = $this->ckey($key); + if (apc_exists($key)) + apc_delete($key); + return apc_store($key, $data); + } + // update existing cache record if ($this->cache_keys[$key]) { $this->db->query( @@ -314,7 +336,11 @@ class rcube_cache } if ($this->type == 'memcache') { - return $this->db->delete($this->mc_key($key)); + return $this->db->delete($this->ckey($key)); + } + + if ($this->type == 'apc') { + return apc_delete($this->ckey($key)); } $this->db->query( @@ -328,12 +354,12 @@ class rcube_cache /** - * Creates per-user Memcache key + * Creates per-user cache key (for memcache and apc) * * @param string $key Cache key * @access private */ - private function mc_key($key) + private function ckey($key) { return sprintf('[%d]%s', $this->userid, $key); } diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index 413a67253..882834ec8 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -3738,7 +3738,7 @@ class rcube_imap /** * Enable or disable indexes caching * - * @param boolean $type Cache type (memcache' or 'db') + * @param boolean $type Cache type (@see rcmail::get_cache) * @access public */ function set_caching($type) |