Changeset 657


Ignore:
Timestamp:
08/05/2011 02:22:08 AM (10 months ago)
Author:
ofer
Message:

Support for memcached

Location:
trunk/WordPress/plugin/transposh
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/core/constants.php

    r645 r657  
    2121define('TP_ENABLE_CACHE', TRUE); 
    2222//What is the cache items TTL 
    23 define('TP_CACHE_TTL', 3600); 
     23define('TP_CACHE_TTL', 3600*24); 
     24//Constants for memcached 
     25define('TP_MEMCACHED_SRV', '127.0.0.1'); 
     26define('TP_MEMCACHED_PORT', 11211); 
    2427 
    2528//Class marking a section not be translated. 
  • trunk/WordPress/plugin/transposh/wp/transposh_admin.php

    r653 r657  
    232232        } 
    233233 
    234         if (!function_exists('apc_fetch') && !function_exists('xcache_get') && !function_exists('eaccelerator_get')) { 
     234        if (!(class_exists('Memcache') && @$this->memcache->connect(TP_MEMCACHED_SRV, TP_MEMCACHED_PORT)) && !function_exists('apc_fetch') && !function_exists('xcache_get') && !function_exists('eaccelerator_get')) { 
    235235            $this->add_warning('tp_cache_warning', __('We were not able to find a supported in-memory caching engine, installing one can improve performance.', TRANSPOSH_TEXT_DOMAIN) . ' <a href="http://transposh.org/faq#performance">' . __('Check Transposh FAQs', TRANSPOSH_TEXT_DOMAIN) . '</a>'); 
    236236        } 
  • trunk/WordPress/plugin/transposh/wp/transposh_db.php

    r604 r657  
    4040    /** @var string translation log table name */ 
    4141    private $translation_log_table; 
     42    /** @var boolean is memcached working */ 
     43    private $memcache_working = false; 
     44    /** @var Memcache the memcached connection object */ 
     45    private $memcache; 
    4246 
    4347    /** 
     
    4852        $this->translation_table = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE; 
    4953        $this->translation_log_table = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG; 
     54 
     55        if (class_exists('Memcache')) { 
     56            logger('I am using memcached!', 3); 
     57            $this->memcache_working = true; 
     58            $this->memcache = new Memcache; 
     59            @$this->memcache->connect(TP_MEMCACHED_SRV, TP_MEMCACHED_PORT) or $this->memcache_working = false; 
     60            logger($this->memcache_working); 
     61        } 
    5062    } 
    5163 
     
    6072        $cached = false; 
    6173        $key = $lang . '_' . $original; 
    62         if (function_exists('apc_fetch')) { 
     74        if ($this->memcache_working) { 
     75            $cached = $this->memcache->get($key); 
     76            logger('memcached', 5); 
     77        } elseif (function_exists('apc_fetch')) { 
    6378            $cached = apc_fetch($key, $rc); 
    6479            if ($rc === false) return false; 
     
    94109        if ($translated !== null) $translated = implode('_', $translated); 
    95110        $rc = false; 
    96         if (function_exists('apc_store')) { 
     111        if ($this->memcache_working) { 
     112            $rc = $this->memcache->set($key, $translated); //, time() + $ttl); 
     113        } elseif (function_exists('apc_store')) { 
    97114            $rc = apc_store($key, $translated, $ttl); 
    98115        } elseif (function_exists('xcache_set')) { 
     
    118135        if (!TP_ENABLE_CACHE) return; 
    119136        $key = $lang . '_' . $original; 
    120         if (function_exists('apc_delete')) { 
     137        if ($this->memcache_working) { 
     138            $this->memcache->delete($key); 
     139        } elseif (function_exists('apc_delete')) { 
    121140            apc_delete($key); 
    122141        } elseif (function_exists('xcache_unset')) { 
     
    132151    function cache_clean() { 
    133152        if (!TP_ENABLE_CACHE) return; 
    134         if (function_exists('apc_clear_cache')) { 
     153        if ($this->memcache_working) { 
     154            $this->memcache->flush(); 
     155        } elseif (function_exists('apc_clear_cache')) { 
    135156            apc_clear_cache('user'); 
    136157        } elseif (function_exists('xcache_unset_by_prefix')) { 
Note: See TracChangeset for help on using the changeset viewer.