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
|
* @access private
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $hostname = null;
|
private $hostname = 'localhost';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Port to use to connect
|
* Port to use to connect
|
||||||
|
@ -48,7 +48,15 @@ class Cache extends Object
|
||||||
* @access private
|
* @access private
|
||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
private $port = null;
|
private $port = 11211;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace (prefix)
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $namespace = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connection resource to Memcached
|
* Connection resource to Memcached
|
||||||
|
@ -76,13 +84,20 @@ class Cache extends Object
|
||||||
{
|
{
|
||||||
$datasource = $this->config->datasources[$this->config->pickles['cache']];
|
$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'];
|
if (isset($datasource[$variable]))
|
||||||
$this->port = $datasource['port'];
|
{
|
||||||
|
$this->$variable = $datasource[$variable];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->namespace != '')
|
||||||
|
{
|
||||||
|
$this->namespace .= '-';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -140,7 +155,7 @@ class Cache extends Object
|
||||||
{
|
{
|
||||||
if ($this->open())
|
if ($this->open())
|
||||||
{
|
{
|
||||||
return $this->connection->get($key);
|
return $this->connection->get($this->namespace . $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -164,7 +179,7 @@ class Cache extends Object
|
||||||
{
|
{
|
||||||
if ($this->open())
|
if ($this->open())
|
||||||
{
|
{
|
||||||
return $this->connection->set($key, $value, 0, $expire);
|
return $this->connection->set($this->namespace . $key, $value, 0, $expire);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -182,7 +197,7 @@ class Cache extends Object
|
||||||
{
|
{
|
||||||
if ($this->open())
|
if ($this->open())
|
||||||
{
|
{
|
||||||
return $this->connection->delete($key);
|
return $this->connection->delete($this->namespace . $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -201,7 +216,7 @@ class Cache extends Object
|
||||||
{
|
{
|
||||||
if ($this->open())
|
if ($this->open())
|
||||||
{
|
{
|
||||||
return $this->connection->increment($key);
|
return $this->connection->increment($this->namespace . $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
33
jar.php
33
jar.php
|
@ -473,7 +473,7 @@ class Cache extends Object
|
||||||
* @access private
|
* @access private
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $hostname = null;
|
private $hostname = 'localhost';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Port to use to connect
|
* Port to use to connect
|
||||||
|
@ -481,7 +481,15 @@ class Cache extends Object
|
||||||
* @access private
|
* @access private
|
||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
private $port = null;
|
private $port = 11211;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Namespace (prefix)
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $namespace = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connection resource to Memcached
|
* Connection resource to Memcached
|
||||||
|
@ -509,13 +517,20 @@ class Cache extends Object
|
||||||
{
|
{
|
||||||
$datasource = $this->config->datasources[$this->config->pickles['cache']];
|
$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'];
|
if (isset($datasource[$variable]))
|
||||||
$this->port = $datasource['port'];
|
{
|
||||||
|
$this->$variable = $datasource[$variable];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->namespace != '')
|
||||||
|
{
|
||||||
|
$this->namespace .= '-';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -573,7 +588,7 @@ class Cache extends Object
|
||||||
{
|
{
|
||||||
if ($this->open())
|
if ($this->open())
|
||||||
{
|
{
|
||||||
return $this->connection->get($key);
|
return $this->connection->get($this->namespace . $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -597,7 +612,7 @@ class Cache extends Object
|
||||||
{
|
{
|
||||||
if ($this->open())
|
if ($this->open())
|
||||||
{
|
{
|
||||||
return $this->connection->set($key, $value, 0, $expire);
|
return $this->connection->set($this->namespace . $key, $value, 0, $expire);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -615,7 +630,7 @@ class Cache extends Object
|
||||||
{
|
{
|
||||||
if ($this->open())
|
if ($this->open())
|
||||||
{
|
{
|
||||||
return $this->connection->delete($key);
|
return $this->connection->delete($this->namespace . $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -634,7 +649,7 @@ class Cache extends Object
|
||||||
{
|
{
|
||||||
if ($this->open())
|
if ($this->open())
|
||||||
{
|
{
|
||||||
return $this->connection->increment($key);
|
return $this->connection->increment($this->namespace . $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue