diff --git a/classes/Cache.php b/classes/Cache.php index 2d9458b..6591311 100644 --- a/classes/Cache.php +++ b/classes/Cache.php @@ -40,7 +40,7 @@ class Cache extends Object * @access private * @var string */ - private $hostname = null; + private $hostname = 'localhost'; /** * Port to use to connect @@ -48,7 +48,15 @@ class Cache extends Object * @access private * @var integer */ - private $port = null; + private $port = 11211; + + /** + * Namespace (prefix) + * + * @access private + * @var string + */ + private $namespace = ''; /** * Connection resource to Memcached @@ -76,13 +84,20 @@ class Cache extends Object { $datasource = $this->config->datasources[$this->config->pickles['cache']]; - if (isset($datasource['hostname'], $datasource['port'])) + foreach (array('hostname', 'port', 'namespace') as $variable) { - $this->hostname = $datasource['hostname']; - $this->port = $datasource['port']; + if (isset($datasource[$variable])) + { + $this->$variable = $datasource[$variable]; + } } } } + + if ($this->namespace != '') + { + $this->namespace .= '-'; + } } /** @@ -140,7 +155,7 @@ class Cache extends Object { if ($this->open()) { - return $this->connection->get($key); + return $this->connection->get($this->namespace . $key); } return false; @@ -164,7 +179,7 @@ class Cache extends Object { if ($this->open()) { - return $this->connection->set($key, $value, 0, $expire); + return $this->connection->set($this->namespace . $key, $value, 0, $expire); } return false; @@ -182,7 +197,7 @@ class Cache extends Object { if ($this->open()) { - return $this->connection->delete($key); + return $this->connection->delete($this->namespace . $key); } return false; @@ -201,7 +216,7 @@ class Cache extends Object { if ($this->open()) { - return $this->connection->increment($key); + return $this->connection->increment($this->namespace . $key); } return false; diff --git a/jar.php b/jar.php index fbd712d..09cb243 100755 --- a/jar.php +++ b/jar.php @@ -473,7 +473,7 @@ class Cache extends Object * @access private * @var string */ - private $hostname = null; + private $hostname = 'localhost'; /** * Port to use to connect @@ -481,7 +481,15 @@ class Cache extends Object * @access private * @var integer */ - private $port = null; + private $port = 11211; + + /** + * Namespace (prefix) + * + * @access private + * @var string + */ + private $namespace = ''; /** * Connection resource to Memcached @@ -509,13 +517,20 @@ class Cache extends Object { $datasource = $this->config->datasources[$this->config->pickles['cache']]; - if (isset($datasource['hostname'], $datasource['port'])) + foreach (array('hostname', 'port', 'namespace') as $variable) { - $this->hostname = $datasource['hostname']; - $this->port = $datasource['port']; + if (isset($datasource[$variable])) + { + $this->$variable = $datasource[$variable]; + } } } } + + if ($this->namespace != '') + { + $this->namespace .= '-'; + } } /** @@ -573,7 +588,7 @@ class Cache extends Object { if ($this->open()) { - return $this->connection->get($key); + return $this->connection->get($this->namespace . $key); } return false; @@ -597,7 +612,7 @@ class Cache extends Object { if ($this->open()) { - return $this->connection->set($key, $value, 0, $expire); + return $this->connection->set($this->namespace . $key, $value, 0, $expire); } return false; @@ -615,7 +630,7 @@ class Cache extends Object { if ($this->open()) { - return $this->connection->delete($key); + return $this->connection->delete($this->namespace . $key); } return false; @@ -634,7 +649,7 @@ class Cache extends Object { if ($this->open()) { - return $this->connection->increment($key); + return $this->connection->increment($this->namespace . $key); } return false;