From 9dde1c08dd03b50299cf371f1022bb02573cef0b Mon Sep 17 00:00:00 2001 From: Tom Schlick Date: Tue, 3 May 2011 03:22:37 -0400 Subject: [PATCH] general cleanup & adding the set() method --- libraries/memcached_library.php | 55 ++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/libraries/memcached_library.php b/libraries/memcached_library.php index 131c936..6bc287b 100644 --- a/libraries/memcached_library.php +++ b/libraries/memcached_library.php @@ -116,11 +116,53 @@ public function add($key = NULL, $value = NULL, $expiration = NULL) case 'Memcache': $add_status = $this->m->add($this->key_name($key), $value, $this->config['config']['compression'], $expiration); break; + + default: case 'Memcached': $add_status = $this->m->add($this->key_name($key), $value, $expiration); break; + } + + return $add_status; + } + } + + /* + +-------------------------------------+ + Name: set + Purpose: similar to the add() method but uses set + @param return : TRUE or FALSE + +-------------------------------------+ + */ + public function set($key = NULL, $value = NULL, $expiration = NULL) + { + if(is_null($expiration)) + { + $expiration = $this->config['config']['expiration']; + } + if(is_array($key)) + { + foreach($key as $multi) + { + if(!isset($multi['expiration']) || $multi['expiration'] == '') + { + $multi['expiration'] = $this->config['config']['expiration']; + } + $this->set($this->key_name($multi['key']), $multi['value'], $multi['expiration']); + } + } + else + { + $this->local_cache[$this->key_name($key)] = $value; + switch($this->client_type) + { + case 'Memcache': + $add_status = $this->m->set($this->key_name($key), $value, $this->config['config']['compression'], $expiration); + break; + default: - $add_status = $this->m->add($this->key_name($key), $value, $expiration); + case 'Memcached': + $add_status = $this->m->set($this->key_name($key), $value, $expiration); break; } @@ -233,10 +275,9 @@ public function replace($key = NULL, $value = NULL, $expiration = NULL) case 'Memcache': $replace_status = $this->m->replace($this->key_name($key), $value, $this->config['config']['compression'], $expiration); break; - case 'Memcached': - $replace_status = $this->m->replace($this->key_name($key), $value, $expiration); - break; + default: + case 'Memcached': $replace_status = $this->m->replace($this->key_name($key), $value, $expiration); break; } @@ -284,10 +325,9 @@ public function getstats($type="items") case 'Memcache': $stats = $this->m->getStats($type); break; - case 'Memcached': - $stats = $this->m->getStats(); - break; + default: + case 'Memcached': $stats = $this->m->getStats(); break; } @@ -308,6 +348,7 @@ public function setcompressthreshold($tresh, $savings=0.2) case 'Memcache': $setcompressthreshold_status = $this->m->setCompressThreshold($tresh, $savings=0.2); break; + default: $setcompressthreshold_status = TRUE; break;