diff --git a/src/EpiCache_Memcached.php b/src/EpiCache_Memcached.php index 42e39c4..98022ff 100644 --- a/src/EpiCache_Memcached.php +++ b/src/EpiCache_Memcached.php @@ -10,9 +10,9 @@ class EpiCache_Memcached extends EpiCache public function __construct($params = array()) { $this->host = !empty($params[0]) ? $params[0] : 'localhost'; - $this->port = !empty($params[1]) ? $params[1] : 11211;; - $this->compress = !empty($params[2]) ? $params[2] : 0;; - $this->expiry = !empty($params[3]) ? $params[3] : 3600; + $this->port = !empty($params[1]) ? $params[1] : 11211; + $this->compress = isset($params[2]) ? $params[2] : 0; + $this->expiry = isset($params[3]) ? $params[3] : 3600; } public function delete($key, $timeout = 0) diff --git a/src/EpiSession_Memcached.php b/src/EpiSession_Memcached.php index 8ecdae1..fe324fe 100644 --- a/src/EpiSession_Memcached.php +++ b/src/EpiSession_Memcached.php @@ -2,21 +2,26 @@ class EpiSession_Memcached implements EpiSessionInterface { private static $connected = false; - private $key = null; - private $store= null; + private $memcached = false; + private $key = null; + private $store = null; + private $host = null; + private $port = null; + private $compress = null; + private $expiry = null; public function __construct($params = array()) { if(empty($_COOKIE[EpiSession::COOKIE])) { - $cookieVal = md5(uniqid(rand(), true)); - setcookie(EpiSession::COOKIE, $cookieVal, time()+1209600, '/'); - $_COOKIE[EpiSession::COOKIE] = $cookieVal; + $key = md5(uniqid(rand(), true)); + setcookie(EpiSession::COOKIE, $key, time() + 1209600, '/'); + $_COOKIE[EpiSession::COOKIE] = $key; } $this->host = !empty($params[0]) ? $params[0] : 'localhost'; - $this->port = !empty($params[1]) ? $params[1] : 11211;; - $this->compress = !empty($params[2]) ? $params[2] : 0;; - $this->expiry = !empty($params[3]) ? $params[3] : 3600; + $this->port = !empty($params[1]) ? $params[1] : 11211; + $this->compress = isset($params[2]) ? $params[2] : 0; + $this->expiry = isset($params[3]) ? $params[3] : 3600; } public function end() @@ -51,7 +56,7 @@ public function set($key = null, $value = null) return false; $this->store[$key] = $value; - $this->memcached->set($this->key, $this->store); + $this->memcached->set($this->key, $this->store, $this->expiry); return $value; } @@ -66,7 +71,7 @@ private function connect($params = null) if($this->memcached->addServer($this->host, $this->port)) { self::$connected = true; - $this->key = empty($key) ? $_COOKIE[EpiSession::COOKIE] : $key; + $this->key = $_COOKIE[EpiSession::COOKIE]; $this->store = $this->getAll(); return true; }