diff options
author | rojaro <> | 2009-09-30 19:48:11 +0000 |
---|---|---|
committer | rojaro <> | 2009-09-30 19:48:11 +0000 |
commit | 2cafbde28d28413155714d6abc90dc271768f189 (patch) | |
tree | a5884e454636b7e83ce91befceb1676391fe10ae /framework/Caching/TMemCache.php | |
parent | 3199d1e928621f245b2c5d9ceea6b77090c5edeb (diff) |
merged TMemCache_Threshold.patch written by E.Letard from #155
Diffstat (limited to 'framework/Caching/TMemCache.php')
-rw-r--r-- | framework/Caching/TMemCache.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/framework/Caching/TMemCache.php b/framework/Caching/TMemCache.php index 0f0ac26d..70a43a2d 100644 --- a/framework/Caching/TMemCache.php +++ b/framework/Caching/TMemCache.php @@ -73,6 +73,9 @@ * where {@link getHost Host} and {@link getPort Port} are configurable properties * of TMemCache. * + * Automatic compression of values may be used (using zlib extension) by setting {@link getThreshold Threshold} and {@link getMinSavings MinSavings} properties. + * NB : MemCache server(s) must be restarted to apply settings. Require (PECL memcache >= 2.0.0). + * * @author Qiang Xue <qiang.xue@gmail.com> * @version $Id$ * @package System.Caching @@ -114,6 +117,15 @@ class TMemCache extends TCache private $_timeout = 360; private $_retryInterval = 15; + /** + * @var integer Controls the minimum value length before attempting to compress automatically. + */ + private $_threshold=0; + + /** + * @var float Specifies the minimum amount of savings to actually store the value compressed. The supplied value must be between 0 and 1. Default value is 0.2 giving a minimum 20% compression savings. + */ + private $_minSavings=0.0; private $_status = true; @@ -165,6 +177,8 @@ class TMemCache extends TCache if($this->_cache->addServer($this->_host,$this->_port)===false) throw new TConfigurationException('memcache_connection_failed',$this->_host,$this->_port); } + if($this->_threshold!==0) + $this->_cache->setCompressThreshold($this->_threshold,$this->_minSavings); $this->_initialized=true; parent::init($config); } @@ -248,6 +262,46 @@ class TMemCache extends TCache } /** + * @return integer minimum value length before attempting to compress + */ + public function getThreshold() + { + return $this->_threshold; + } + + /** + * @param integer minimum value length before attempting to compress + * @throws TInvalidOperationException if the module is already initialized + */ + public function setThreshold($value) + { + if($this->_initialized) + throw new TInvalidOperationException('memcache_threshold_unchangeable'); + else + $this->_threshold=TPropertyValue::ensureInteger($value); + } + + /** + * @return float minimum amount of savings to actually store the value compressed + */ + public function getMinSavings() + { + return $this->_minSavings; + } + + /** + * @param float minimum amount of savings to actually store the value compressed + * @throws TInvalidOperationException if the module is already initialized + */ + public function setMinSavings($value) + { + if($this->_initialized) + throw new TInvalidOperationException('memcache_min_savings_unchangeable'); + else + $this->_minSavings=TPropertyValue::ensureFloat($value); + } + + /** * Retrieves a value from cache with a specified key. * This is the implementation of the method declared in the parent class. * @param string a unique key identifying the cached value |