Support implicit sectioned caching using :: syntax.
This commit is contained in:
parent
4d2ecdbff2
commit
31106a9211
|
@ -16,6 +16,20 @@ class Memcached extends Driver implements Sectionable {
|
||||||
*/
|
*/
|
||||||
protected $key;
|
protected $key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that section caching is implicit based on keys.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $implicit = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The implicit section key delimiter.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $delimiter = '::';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Memcached cache driver instance.
|
* Create a new Memcached cache driver instance.
|
||||||
*
|
*
|
||||||
|
@ -47,7 +61,13 @@ public function has($key)
|
||||||
*/
|
*/
|
||||||
protected function retrieve($key)
|
protected function retrieve($key)
|
||||||
{
|
{
|
||||||
if (($cache = $this->memcache->get($this->key.$key)) !== false)
|
if ($this->sectionable($key))
|
||||||
|
{
|
||||||
|
list($section, $key) = $this->parse($key);
|
||||||
|
|
||||||
|
return $this->get_from_section($section, $key);
|
||||||
|
}
|
||||||
|
elseif (($cache = $this->memcache->get($this->key.$key)) !== false)
|
||||||
{
|
{
|
||||||
return $cache;
|
return $cache;
|
||||||
}
|
}
|
||||||
|
@ -80,9 +100,18 @@ public function get_from_section($section, $key, $default = null)
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function put($key, $value, $minutes)
|
public function put($key, $value, $minutes)
|
||||||
|
{
|
||||||
|
if ($this->sectionable($key))
|
||||||
|
{
|
||||||
|
list($section, $key) = $this->parse($key);
|
||||||
|
|
||||||
|
return $this->put_in_section($section, $key, $value, $minutes);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
$this->memcache->set($this->key.$key, $value, $minutes * 60);
|
$this->memcache->set($this->key.$key, $value, $minutes * 60);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a sectioned item to the cache.
|
* Write a sectioned item to the cache.
|
||||||
|
@ -106,9 +135,18 @@ public function put_in_section($section, $key, $value, $minutes)
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function forever($key, $value)
|
public function forever($key, $value)
|
||||||
|
{
|
||||||
|
if ($this->sectionable($key))
|
||||||
|
{
|
||||||
|
list($section, $key) = $this->parse($key);
|
||||||
|
|
||||||
|
return $this->forever_in_section($section, $key, $value);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return $this->put($key, $value, 0);
|
return $this->put($key, $value, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a sectioned item to the cache that lasts forever.
|
* Write a sectioned item to the cache that lasts forever.
|
||||||
|
@ -159,9 +197,25 @@ public function sear_in_section($section, $key, $default)
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function forget($key)
|
public function forget($key)
|
||||||
|
{
|
||||||
|
if ($this->sectionable($key))
|
||||||
|
{
|
||||||
|
list($section, $key) = $this->parse($key);
|
||||||
|
|
||||||
|
if ($key == '*')
|
||||||
|
{
|
||||||
|
$this->forget_section($section);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->forget_in_section($section, $key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
$this->memcache->delete($this->key.$key);
|
$this->memcache->delete($this->key.$key);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a sectioned item from the cache.
|
* Delete a sectioned item from the cache.
|
||||||
|
@ -223,6 +277,17 @@ protected function section_item_key($section, $key)
|
||||||
return $section.'#'.$this->section_id($section).'#'.$key;
|
return $section.'#'.$this->section_id($section).'#'.$key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if a key is sectionable.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function sectionable($key)
|
||||||
|
{
|
||||||
|
return $this->implicit and $this->sectioned($key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a key is sectioned.
|
* Determine if a key is sectioned.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue