Added namespace/prefix to the caching class
Closes #3 taking the issues down to zero :-O
This commit is contained in:
parent
1154a1d901
commit
4a41a07635
2 changed files with 48 additions and 18 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue