Reformatting code in memcache.

Adding unset() to test case to remove unnecessary keys that can cause test failure.
This commit is contained in:
mark_story 2009-11-14 18:50:23 -05:00
parent 8b1a2b1f72
commit 06d4e5e553
2 changed files with 15 additions and 10 deletions

View file

@ -61,7 +61,10 @@ class MemcacheEngine extends CacheEngine {
return false;
}
parent::init(array_merge(array(
'engine'=> 'Memcache', 'prefix' => Inflector::slug(APP_DIR) . '_', 'servers' => array('127.0.0.1'), 'compress'=> false
'engine'=> 'Memcache',
'prefix' => Inflector::slug(APP_DIR) . '_',
'servers' => array('127.0.0.1'),
'compress'=> false
), $settings)
);
@ -100,7 +103,7 @@ class MemcacheEngine extends CacheEngine {
*/
function write($key, &$value, $duration) {
$expires = time() + $duration;
$this->__Memcache->set($key.'_expires', $expires, $this->settings['compress'], $expires);
$this->__Memcache->set($key . '_expires', $expires, $this->settings['compress'], $expires);
return $this->__Memcache->set($key, $value, $this->settings['compress'], $expires);
}
/**
@ -112,7 +115,7 @@ class MemcacheEngine extends CacheEngine {
*/
function read($key) {
$time = time();
$cachetime = intval($this->__Memcache->get($key.'_expires'));
$cachetime = intval($this->__Memcache->get($key . '_expires'));
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
return false;
}

View file

@ -82,13 +82,15 @@ class MemcacheEngineTest extends CakeTestCase {
*/
function testSettings() {
$settings = Cache::settings();
$expecting = array('prefix' => 'cake_',
'duration'=> 3600,
'probability' => 100,
'servers' => array('127.0.0.1'),
'compress' => false,
'engine' => 'Memcache'
);
unset($settings['serialize'], $settings['path']);
$expecting = array(
'prefix' => 'cake_',
'duration'=> 3600,
'probability' => 100,
'servers' => array('127.0.0.1'),
'compress' => false,
'engine' => 'Memcache'
);
$this->assertEqual($settings, $expecting);
}
/**