From b6ef1305dfcdc957171b5c7fe751d96c90a2127b Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 13 May 2011 22:10:58 -0400 Subject: [PATCH] Backporting changes made to Memcache in 2.0 to address issues with persistent connections. Refs #1705 --- app/config/core.php | 1 + cake/console/templates/skel/config/core.php | 1 + cake/libs/cache/memcache.php | 5 +++-- cake/tests/cases/libs/cache/memcache.test.php | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/config/core.php b/app/config/core.php index 413718e8c..517e32d0d 100644 --- a/app/config/core.php +++ b/app/config/core.php @@ -297,6 +297,7 @@ * '127.0.0.1:11211' // localhost, default port 11211 * ), //[optional] * 'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory) + * 'persistent' => true, // [optional] set this to false for non-persistent connections * )); * */ diff --git a/cake/console/templates/skel/config/core.php b/cake/console/templates/skel/config/core.php index 413718e8c..517e32d0d 100644 --- a/cake/console/templates/skel/config/core.php +++ b/cake/console/templates/skel/config/core.php @@ -297,6 +297,7 @@ * '127.0.0.1:11211' // localhost, default port 11211 * ), //[optional] * 'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory) + * 'persistent' => true, // [optional] set this to false for non-persistent connections * )); * */ diff --git a/cake/libs/cache/memcache.php b/cake/libs/cache/memcache.php index c9616ea7a..a1bcc5c55 100644 --- a/cake/libs/cache/memcache.php +++ b/cake/libs/cache/memcache.php @@ -67,7 +67,8 @@ class MemcacheEngine extends CacheEngine { 'engine'=> 'Memcache', 'prefix' => Inflector::slug(APP_DIR) . '_', 'servers' => array('127.0.0.1'), - 'compress'=> false + 'compress'=> false, + 'persistent' => true ), $settings) ); @@ -82,7 +83,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/cake/tests/cases/libs/cache/memcache.test.php b/cake/tests/cases/libs/cache/memcache.test.php index 8f7715c3c..e3553691d 100644 --- a/cake/tests/cases/libs/cache/memcache.test.php +++ b/cake/tests/cases/libs/cache/memcache.test.php @@ -106,7 +106,8 @@ class MemcacheEngineTest extends CakeTestCase { 'probability' => 100, 'servers' => array('127.0.0.1'), 'compress' => false, - 'engine' => 'Memcache' + 'engine' => 'Memcache', + 'persistent' => true, ); $this->assertEqual($settings, $expecting); }