Changeset fec2d8e in github


Ignore:
Timestamp:
Feb 21, 2012 4:43:39 PM (16 months ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.8
Children:
3c9e903
Parents:
965e6276
Message:

Refactored IMAP cache expunge: delegate to storage object; don't rely on deprecated 'enable_caching' config option

Location:
program/include
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • program/include/main.inc

    re5306ee rfec2d8e  
    156156    closedir($dir); 
    157157  } 
    158 } 
    159  
    160  
    161 /** 
    162  * Garbage collector for cache entries. 
    163  * Remove all expired message cache records 
    164  * @return void 
    165  */ 
    166 function rcmail_cache_gc() 
    167 { 
    168   $rcmail = rcmail::get_instance(); 
    169   $db = $rcmail->get_dbh(); 
    170  
    171   // get target timestamp 
    172   $ts = get_offset_time($rcmail->config->get('message_cache_lifetime', '30d'), -1); 
    173  
    174   $db->query("DELETE FROM ".get_table_name('cache_messages') 
    175         ." WHERE changed < " . $db->fromunixtime($ts)); 
    176  
    177   $db->query("DELETE FROM ".get_table_name('cache_index') 
    178         ." WHERE changed < " . $db->fromunixtime($ts)); 
    179  
    180   $db->query("DELETE FROM ".get_table_name('cache_thread') 
    181         ." WHERE changed < " . $db->fromunixtime($ts)); 
    182  
    183   $db->query("DELETE FROM ".get_table_name('cache') 
    184         ." WHERE created < " . $db->fromunixtime($ts)); 
    185158} 
    186159 
  • program/include/rcmail.php

    ra7321e7 rfec2d8e  
    130130  private $action_map = array(); 
    131131  private $shutdown_functions = array(); 
     132  private $expunge_cache = false; 
    132133 
    133134 
     
    768769 
    769770    $this->session->register_gc_handler('rcmail_temp_gc'); 
    770     if ($this->config->get('enable_caching')) 
    771       $this->session->register_gc_handler('rcmail_cache_gc'); 
     771    $this->session->register_gc_handler(array($this, 'cache_gc')); 
    772772 
    773773    // start PHP session (if not in CLI mode) 
     
    12791279    } 
    12801280 
    1281     if (is_object($this->storage)) 
     1281    if (is_object($this->storage)) { 
     1282        if ($this->expunge_cache) 
     1283            $this->storage->expunge_cache(); 
    12821284      $this->storage->close(); 
     1285  } 
    12831286 
    12841287    // before closing the database connection, write session data 
     
    13131316  { 
    13141317    $this->shutdown_functions[] = $function; 
     1318  } 
     1319 
     1320 
     1321  /** 
     1322   * Garbage collector for cache entries. 
     1323   * Set flag to expunge caches on shutdown 
     1324   */ 
     1325  function cache_gc() 
     1326  { 
     1327    // because this gc function is called before storage is initialized, 
     1328    // we just set a flag to expunge storage cache on shutdown. 
     1329    $this->expunge_cache = true; 
    13151330  } 
    13161331 
  • program/include/rcube_imap.php

    rb3ad480 rfec2d8e  
    35283528        if ($this->caching && !$this->cache) { 
    35293529            $rcmail = rcmail::get_instance(); 
    3530             $this->cache = $rcmail->get_cache('IMAP', $this->caching); 
     3530            $ttl = $rcmail->config->get('message_cache_lifetime', '10d') - mktime(); 
     3531            $this->cache = $rcmail->get_cache('IMAP', $this->caching, $ttl); 
    35313532        } 
    35323533 
     
    35733574            $cache->remove($key, $prefix_mode); 
    35743575        } 
     3576    } 
     3577 
     3578    /** 
     3579     * Delete outdated cache entries 
     3580     */ 
     3581    public function expunge_cache() 
     3582    { 
     3583        if ($this->mcache) { 
     3584            $ttl = rcmail::get_instance()->config->get('message_cache_lifetime', '10d'); 
     3585            $this->mcache->expunge($ttl); 
     3586        } 
     3587 
     3588        if ($this->cache) 
     3589            $this->cache->expunge(); 
    35753590    } 
    35763591 
  • program/include/rcube_imap_cache.php

    r7fe3811 rfec2d8e  
    600600 
    601601    /** 
     602     * Delete cache entries older than TTL 
     603     * 
     604     * @param string $ttl  Lifetime of message cache entries 
     605     */ 
     606    function expunge($ttl) 
     607    { 
     608        // get expiration timestamp 
     609        $ts = get_offset_time($ttl, -1); 
     610 
     611        $this->db->query("DELETE FROM ".get_table_name('cache_messages') 
     612              ." WHERE changed < " . $this->db->fromunixtime($ts)); 
     613 
     614        $this->db->query("DELETE FROM ".get_table_name('cache_index') 
     615              ." WHERE changed < " . $this->db->fromunixtime($ts)); 
     616 
     617        $this->db->query("DELETE FROM ".get_table_name('cache_thread') 
     618              ." WHERE changed < " . $this->db->fromunixtime($ts)); 
     619    } 
     620 
     621 
     622    /** 
    602623     * Fetches index data from database 
    603624     */ 
  • program/include/rcube_session.php

    r7fe3811 rfec2d8e  
    333333   * @param mixed Callback function 
    334334   */ 
    335   public function register_gc_handler($func_name) 
    336   { 
    337     if ($func_name && !in_array($func_name, $this->gc_handlers)) 
    338       $this->gc_handlers[] = $func_name; 
     335  public function register_gc_handler($func) 
     336  { 
     337    foreach ($this->gc_handlers as $handler) { 
     338      if ($handler == $func) { 
     339        return; 
     340      } 
     341    } 
     342 
     343    $this->gc_handlers[] = $func; 
    339344  } 
    340345 
  • program/include/rcube_storage.php

    r7fe3811 rfec2d8e  
    972972    abstract function get_cache($key); 
    973973 
     974    /** 
     975     * Delete outdated cache entries 
     976     */ 
     977    abstract function expunge_cache(); 
     978 
    974979}  // end class rcube_storage 
    975980 
Note: See TracChangeset for help on using the changeset viewer.