Changeset 4785 in subversion


Ignore:
Timestamp:
May 18, 2011 8:37:00 AM (2 years ago)
Author:
alec
Message:
  • Add APC support in rcube_cache
Location:
trunk/roundcubemail
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r4783 r4785  
    22=========================== 
    33 
    4 - Added general rcube_cache class with memcache support 
     4- Added general rcube_cache class with Memcache and APC support 
    55- Improved caching performance by skipping writes of unchanged data 
    66- Option enable_caching replaced by imap_cache and messages_cache options 
  • trunk/roundcubemail/config/main.inc.php.dist

    r4783 r4785  
    110110$rcmail_config['imap_auth_pw'] = null; 
    111111 
    112 // Type of IMAP indexes cache. Supported values: 'db' and 'memcache'. 
     112// Type of IMAP indexes cache. Supported values: 'db', 'apc' and 'memcache'. 
    113113$rcmail_config['imap_cache'] = null; 
    114114 
  • trunk/roundcubemail/program/include/rcmail.php

    r4783 r4785  
    357357   * 
    358358   * @param string $name Cache identifier 
    359    * @param string $type Cache type ('db' or 'memcache') 
     359   * @param string $type Cache type ('db', 'apc' or 'memcache') 
    360360   * 
    361361   * @return rcube_cache Cache object 
  • trunk/roundcubemail/program/include/rcube_cache.php

    r4784 r4785  
    5252     * Object constructor. 
    5353     * 
    54      * @param string $type   Engine type ('db' or 'memcache') 
     54     * @param string $type   Engine type ('db' or 'memcache' or 'apc') 
    5555     * @param int    $userid User identifier 
    5656     * @param string $prefix Key name prefix 
     
    5959    { 
    6060        $rcmail = rcmail::get_instance(); 
     61        $type   = strtolower($type); 
    6162     
    62         if (strtolower($type) == 'memcache') { 
     63        if ($type == 'memcache') { 
    6364            $this->type = 'memcache'; 
    6465            $this->db   = $rcmail->get_memcache(); 
     66        } 
     67        else if ($type == 'apc') { 
     68            $this->type = 'apc'; 
     69            $this->db   = function_exists('apc_exists'); // APC 3.1.4 required 
    6570        } 
    6671        else { 
     
    209214 
    210215        if ($this->type == 'memcache') { 
    211             $data = $this->db->get($this->mc_key($key)); 
     216            $data = $this->db->get($this->ckey($key)); 
     217                 
     218            if ($data) { 
     219                $this->cache_sums[$key] = md5($data); 
     220                $data = unserialize($data); 
     221            } 
     222            return $this->cache[$key] = $data; 
     223        } 
     224 
     225        if ($this->type == 'apc') { 
     226            $data = apc_fetch($this->ckey($key)); 
    212227                 
    213228            if ($data) { 
     
    264279 
    265280        if ($this->type == 'memcache') { 
    266             $key = $this->mc_key($key); 
     281            $key = $this->ckey($key); 
    267282            $result = $this->db->replace($key, $data, MEMCACHE_COMPRESSED); 
    268283            if (!$result) 
    269284                $result = $this->db->set($key, $data, MEMCACHE_COMPRESSED); 
    270285            return $result; 
     286        } 
     287 
     288        if ($this->type == 'apc') { 
     289            $key = $this->ckey($key); 
     290            if (apc_exists($key)) 
     291                apc_delete($key); 
     292            return apc_store($key, $data); 
    271293        } 
    272294 
     
    315337 
    316338        if ($this->type == 'memcache') { 
    317             return $this->db->delete($this->mc_key($key)); 
     339            return $this->db->delete($this->ckey($key)); 
     340        } 
     341 
     342        if ($this->type == 'apc') { 
     343            return apc_delete($this->ckey($key)); 
    318344        } 
    319345 
     
    329355 
    330356    /** 
    331      * Creates per-user Memcache key 
     357     * Creates per-user cache key (for memcache and apc) 
    332358     * 
    333359     * @param string $key Cache key 
    334360     * @access private 
    335361     */ 
    336     private function mc_key($key) 
     362    private function ckey($key) 
    337363    { 
    338364        return sprintf('[%d]%s', $this->userid, $key); 
  • trunk/roundcubemail/program/include/rcube_imap.php

    r4783 r4785  
    37393739     * Enable or disable indexes caching 
    37403740     * 
    3741      * @param boolean $type Cache type (memcache' or 'db') 
     3741     * @param boolean $type Cache type (@see rcmail::get_cache) 
    37423742     * @access public 
    37433743     */ 
Note: See TracChangeset for help on using the changeset viewer.