From 402c4a7a6fb171c59cb445ff7c9f7c16f9f1851f Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Fri, 13 May 2011 23:44:51 +0200 Subject: [PATCH 1/2] Added 'persistent' setting to MemcacheEngine. Fixes #1705 when connections are not closed when using i.e. FCGI. --- app/config/core.php | 1 + lib/Cake/Cache/Engine/MemcacheEngine.php | 3 ++- lib/Cake/tests/Case/Cache/Engine/MemcacheTest.php | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/config/core.php b/app/config/core.php index b41657f4c..f0518372a 100644 --- a/app/config/core.php +++ b/app/config/core.php @@ -279,6 +279,7 @@ * 'servers' => array( * '127.0.0.1:11211' // localhost, default port 11211 * ), //[optional] + * 'persistent' => true // [optional] set this to false for non-persistent connections (i.e. when using fcgi) * 'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory) * )); * diff --git a/lib/Cake/Cache/Engine/MemcacheEngine.php b/lib/Cake/Cache/Engine/MemcacheEngine.php index 34ee10043..d81807948 100644 --- a/lib/Cake/Cache/Engine/MemcacheEngine.php +++ b/lib/Cake/Cache/Engine/MemcacheEngine.php @@ -64,6 +64,7 @@ class MemcacheEngine extends CacheEngine { 'engine'=> 'Memcache', 'prefix' => Inflector::slug(APP_DIR) . '_', 'servers' => array('127.0.0.1'), + 'persistent' => true, 'compress'=> false ), $settings) ); @@ -79,7 +80,7 @@ class MemcacheEngine extends CacheEngine { $this->_Memcache = new Memcache(); foreach ($this->settings['servers'] as $server) { list($host, $port) = $this->_parseServerString($server); - if ($this->_Memcache->addServer($host, $port)) { + if ($this->_Memcache->addServer($host, $port, $this->settings['persistent'])) { $return = true; } } diff --git a/lib/Cake/tests/Case/Cache/Engine/MemcacheTest.php b/lib/Cake/tests/Case/Cache/Engine/MemcacheTest.php index ada9c52bc..c402509f6 100644 --- a/lib/Cake/tests/Case/Cache/Engine/MemcacheTest.php +++ b/lib/Cake/tests/Case/Cache/Engine/MemcacheTest.php @@ -50,7 +50,7 @@ class MemcacheEngineTest extends CakeTestCase { * @return void */ function setUp() { - $this->skipIf(!class_exists('Memcache'), '%s Apc is not installed or configured properly'); + $this->skipIf(!class_exists('Memcache'), '%s Memcache is not installed or configured properly'); $this->_cacheDisable = Configure::read('Cache.disable'); Configure::write('Cache.disable', false); Cache::config('memcache', array( @@ -86,6 +86,7 @@ class MemcacheEngineTest extends CakeTestCase { 'duration'=> 3600, 'probability' => 100, 'servers' => array('127.0.0.1'), + 'persistent' => true, 'compress' => false, 'engine' => 'Memcache' ); From 4aa92543165cae71e26f80c66136eb960c197659 Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Sat, 14 May 2011 00:55:28 +0200 Subject: [PATCH 2/2] Updated Memcache settings docblock in core.php (skel and config). Removed probably misleading comment about FCGI. Fixes #1705 --- app/config/core.php | 2 +- lib/Cake/Console/templates/skel/config/core.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/config/core.php b/app/config/core.php index f0518372a..0047f8d2d 100644 --- a/app/config/core.php +++ b/app/config/core.php @@ -279,7 +279,7 @@ * 'servers' => array( * '127.0.0.1:11211' // localhost, default port 11211 * ), //[optional] - * 'persistent' => true // [optional] set this to false for non-persistent connections (i.e. when using fcgi) + * 'persistent' => true, // [optional] set this to false for non-persistent connections * 'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory) * )); * diff --git a/lib/Cake/Console/templates/skel/config/core.php b/lib/Cake/Console/templates/skel/config/core.php index c445896b1..2f20b8174 100644 --- a/lib/Cake/Console/templates/skel/config/core.php +++ b/lib/Cake/Console/templates/skel/config/core.php @@ -279,6 +279,7 @@ * 'servers' => array( * '127.0.0.1:11211' // localhost, default port 11211 * ), //[optional] + * 'persistent' => true, // [optional] set this to false for non-persistent connections * 'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory) * )); *