Changeset 5d66a4b in github


Ignore:
Timestamp:
Apr 19, 2012 3:42:19 AM (13 months ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo
Children:
6c95b3e4
Parents:
6a8b4c2
Message:
  • Improved ttl values handling
Location:
program/include
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcube.php

    r6a8b4c2 r5d66a4b  
    237237   * @param string $name   Cache identifier 
    238238   * @param string $type   Cache type ('db', 'apc' or 'memcache') 
    239    * @param int    $ttl    Expiration time for cache items in seconds 
     239   * @param string $ttl    Expiration time for cache items 
    240240   * @param bool   $packed Enables/disables data serialization 
    241241   * 
  • program/include/rcube_cache.php

    rbe98dfc2 r5d66a4b  
    6060     * @param int    $userid User identifier 
    6161     * @param string $prefix Key name prefix 
    62      * @param int    $ttl    Expiration time of memcache/apc items in seconds (max.2592000) 
     62     * @param string $ttl    Expiration time of memcache/apc items 
    6363     * @param bool   $packed Enables/disabled data serialization. 
    6464     *                       It's possible to disable data serialization if you're sure 
     
    8383        } 
    8484 
     85        // convert ttl string to seconds 
     86        $ttl = get_offset_sec($ttl); 
     87        if ($ttl > 2592000) $ttl = 2592000; 
     88 
    8589        $this->userid    = (int) $userid; 
    86         $this->ttl       = (int) $ttl; 
     90        $this->ttl       = $ttl; 
    8791        $this->packed    = $packed; 
    8892        $this->prefix    = $prefix; 
  • program/include/rcube_imap.php

    r6a8b4c2 r5d66a4b  
    35333533            $rcube = rcube::get_instance(); 
    35343534            $ttl = $rcube->config->get('message_cache_lifetime', '10d'); 
    3535             $ttl = get_offset_time($ttl) - time(); 
    3536  
    35373535            $this->cache = $rcube->get_cache('IMAP', $this->caching, $ttl); 
    35383536        } 
  • program/include/rcube_shared.inc

    r6a8b4c2 r5d66a4b  
    147147 
    148148/** 
    149  * Create a unix timestamp with a specified offset from now. 
    150  * 
    151  * @param string $offset_str  String representation of the offset (e.g. 20min, 5h, 2days) 
    152  * @param int    $factor      Factor to multiply with the offset 
    153  * 
    154  * @return int Unix timestamp 
    155  */ 
    156 function get_offset_time($offset_str, $factor=1) 
    157 { 
    158     if (preg_match('/^([0-9]+)\s*([smhdw])/i', $offset_str, $regs)) { 
    159         $amount = (int)$regs[1]; 
     149 * Returns number of seconds for a specified offset string. 
     150 * 
     151 * @param string $str  String representation of the offset (e.g. 20min, 5h, 2days, 1week) 
     152 * 
     153 * @return int Number of seconds 
     154 */ 
     155function get_offset_sec($str) 
     156{ 
     157    if (preg_match('/^([0-9]+)\s*([smhdw])/i', $str, $regs)) { 
     158        $amount = (int) $regs[1]; 
    160159        $unit   = strtolower($regs[2]); 
    161160    } 
    162161    else { 
    163         $amount = (int)$offset_str; 
     162        $amount = (int) $str; 
    164163        $unit   = 's'; 
    165164    } 
    166165 
    167     $ts = time(); 
    168166    switch ($unit) { 
    169167    case 'w': 
     
    175173    case 'm': 
    176174        $amount *= 60; 
    177     case 's': 
    178         $ts += $amount * $factor; 
    179     } 
    180  
    181     return $ts; 
     175    } 
     176 
     177    return $amount; 
     178} 
     179 
     180 
     181/** 
     182 * Create a unix timestamp with a specified offset from now. 
     183 * 
     184 * @param string $offset_str  String representation of the offset (e.g. 20min, 5h, 2days) 
     185 * @param int    $factor      Factor to multiply with the offset 
     186 * 
     187 * @return int Unix timestamp 
     188 */ 
     189function get_offset_time($offset_str, $factor=1) 
     190{ 
     191    return time() + get_offset_sec($offset_str) * $factor; 
    182192} 
    183193 
Note: See TracChangeset for help on using the changeset viewer.