'localhost', 'port' => 11211, ); /** * Minimal data size to be compressed * @var int */ protected $min_compress = 512; function SugarCache_Memcache() { $config = SugarConfig::getInstance(); $this->_config['host'] = $config->get('external_cache.memcache.host', 'localhost'); $this->_config['port'] = $config->get('external_cache.memcache.port', 11211); } function init() { if (EXTERNAL_CACHE_DEBUG) { SugarCache::log('initializing memcache'); } $this->_memcache = new Memcache(); $status = @$this->_memcache->connect( $this->_config['host'], $this->_config['port'] ); if (!$status) { if (EXTERNAL_CACHE_DEBUG) { SugarCache::log('initialization of memcache failed', 'fail'); } $this->initialized = false; return; } $config = SugarConfig::getInstance(); if($config->get('external_cache.memcache.disable_compression', false)) { $this->_memcache->setCompressThreshold($config->get('external_cache.memcache.min_compression', $this->min_compress)); } else { $this->_memcache->setCompressThreshold(0); } parent::init(); } function get($key) { $value = parent::get($key); if (!is_null($value)) { return $value; } if (EXTERNAL_CACHE_DEBUG) { SugarCache::log('grabbing via Memcache::get(' . $this->_realKey($key) . ')'); } return $this->_processGet( $key, $this->_memcache->get( $this->_realKey($key) ) ); } function set($key, $value) { parent::set($key, $value); // caching is turned off if(!$GLOBALS['external_cache_enabled']) { return; } $external_key = $this->_realKey($key); if (EXTERNAL_CACHE_DEBUG) { SugarCache::log("Step 3: Converting key ($key) to external key ($external_key)"); } $this->_memcache->set($external_key, $value, 0, $this->timeout); if (EXTERNAL_CACHE_DEBUG) { SugarCache::log("Step 4: Added key to memcache cache {$external_key} with value ($value) to be stored for ".EXTERNAL_CACHE_INTERVAL_SECONDS." seconds"); } } function __unset($key) { parent::__unset($key); $this->_memcache->delete($this->_realKey($key)); } }