Cleaned up the section able implementation.
This commit is contained in:
parent
9dea22c3eb
commit
c49c60365f
|
@ -16,20 +16,6 @@ class Memcached extends 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.
|
||||||
*
|
*
|
||||||
|
@ -73,19 +59,6 @@ protected function retrieve($key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve a sectioned item from the cache driver.
|
|
||||||
*
|
|
||||||
* @param string $section
|
|
||||||
* @param string $key
|
|
||||||
* @param mixed $default
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function get_from_section($section, $key, $default = null)
|
|
||||||
{
|
|
||||||
return $this->get($this->section_item_key($section, $key), $default);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write an item to the cache for a given number of minutes.
|
* Write an item to the cache for a given number of minutes.
|
||||||
*
|
*
|
||||||
|
@ -113,20 +86,6 @@ public function put($key, $value, $minutes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Write a sectioned item to the cache.
|
|
||||||
*
|
|
||||||
* @param string $section
|
|
||||||
* @param string $key
|
|
||||||
* @param mixed $value
|
|
||||||
* @param int $minutes
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function put_in_section($section, $key, $value, $minutes)
|
|
||||||
{
|
|
||||||
$this->put($this->section_item_key($section, $key), $value, $minutes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write an item to the cache that lasts forever.
|
* Write an item to the cache that lasts forever.
|
||||||
*
|
*
|
||||||
|
@ -148,48 +107,6 @@ public function forever($key, $value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Write a sectioned item to the cache that lasts forever.
|
|
||||||
*
|
|
||||||
* @param string $section
|
|
||||||
* @param string $key
|
|
||||||
* @param mixed $value
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function forever_in_section($section, $key, $value)
|
|
||||||
{
|
|
||||||
return $this->forever($this->section_item_key($section, $key), $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a sectioned item from the cache, or cache and return the default value.
|
|
||||||
*
|
|
||||||
* @param string $section
|
|
||||||
* @param string $key
|
|
||||||
* @param mixed $default
|
|
||||||
* @param int $minutes
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function remember_in_section($section, $key, $default, $minutes, $function = 'put')
|
|
||||||
{
|
|
||||||
$key = $this->section_item_key($section, $key);
|
|
||||||
|
|
||||||
return $this->remember($key, $default, $minutes, $function);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a sectioned item from the cache, or cache the default value forever.
|
|
||||||
*
|
|
||||||
* @param string $section
|
|
||||||
* @param string $key
|
|
||||||
* @param mixed $default
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function sear_in_section($section, $key, $default)
|
|
||||||
{
|
|
||||||
return $this->sear($this->section_item_key($section, $key), $default);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an item from the cache.
|
* Delete an item from the cache.
|
||||||
*
|
*
|
||||||
|
@ -217,18 +134,6 @@ public function forget($key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a sectioned item from the cache.
|
|
||||||
*
|
|
||||||
* @param string $section
|
|
||||||
* @param string $key
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function forget_in_section($section, $key)
|
|
||||||
{
|
|
||||||
return $this->forget($this->section_item_key($section, $key));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an entire section from the cache.
|
* Delete an entire section from the cache.
|
||||||
*
|
*
|
||||||
|
|
|
@ -28,22 +28,16 @@ public function has($key)
|
||||||
*/
|
*/
|
||||||
protected function retrieve($key)
|
protected function retrieve($key)
|
||||||
{
|
{
|
||||||
return array_get($this->storage, $key);
|
if ($this->sectionable($key))
|
||||||
}
|
{
|
||||||
|
list($section, $key) = $this->parse($key);
|
||||||
|
|
||||||
/**
|
return $this->get_from_section($section, $key);
|
||||||
* Retrieve a sectioned item from the cache driver.
|
}
|
||||||
*
|
else
|
||||||
* @param string $section
|
{
|
||||||
* @param string $key
|
return array_get($this->storage, $key);
|
||||||
* @param mixed $default
|
}
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function get_from_section($section, $key, $default = null)
|
|
||||||
{
|
|
||||||
$key = $this->section_item_key($section, $key);
|
|
||||||
|
|
||||||
return array_get($this->storage, $key, $default);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,21 +55,16 @@ public function get_from_section($section, $key, $default = null)
|
||||||
*/
|
*/
|
||||||
public function put($key, $value, $minutes)
|
public function put($key, $value, $minutes)
|
||||||
{
|
{
|
||||||
array_set($this->storage, $key, $value);
|
if ($this->sectionable($key))
|
||||||
}
|
{
|
||||||
|
list($section, $key) = $this->parse($key);
|
||||||
|
|
||||||
/**
|
return $this->put_in_section($section, $key, $value, $minutes);
|
||||||
* Write a sectioned item to the cache.
|
}
|
||||||
*
|
else
|
||||||
* @param string $section
|
{
|
||||||
* @param string $key
|
array_set($this->storage, $key, $value);
|
||||||
* @param mixed $value
|
}
|
||||||
* @param int $minutes
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function put_in_section($section, $key, $value, $minutes)
|
|
||||||
{
|
|
||||||
$this->put($this->section_item_key($section, $key), $value, $minutes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,49 +76,16 @@ public function put_in_section($section, $key, $value, $minutes)
|
||||||
*/
|
*/
|
||||||
public function forever($key, $value)
|
public function forever($key, $value)
|
||||||
{
|
{
|
||||||
$this->put($key, $value, 0);
|
if ($this->sectionable($key))
|
||||||
}
|
{
|
||||||
|
list($section, $key) = $this->parse($key);
|
||||||
|
|
||||||
/**
|
return $this->forever_in_section($section, $key, $value);
|
||||||
* Write a sectioned item to the cache that lasts forever.
|
}
|
||||||
*
|
else
|
||||||
* @param string $section
|
{
|
||||||
* @param string $key
|
$this->put($key, $value, 0);
|
||||||
* @param mixed $value
|
}
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function forever_in_section($section, $key, $value)
|
|
||||||
{
|
|
||||||
$this->put_in_section($section, $key, $value, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a sectioned item from the cache, or cache and return the default value.
|
|
||||||
*
|
|
||||||
* @param string $section
|
|
||||||
* @param string $key
|
|
||||||
* @param mixed $default
|
|
||||||
* @param int $minutes
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function remember_in_section($section, $key, $default, $minutes, $function = 'put')
|
|
||||||
{
|
|
||||||
$key = $this->section_item_key($section, $key);
|
|
||||||
|
|
||||||
return $this->remember($key, $default, $minutes, $function);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a sectioned item from the cache, or cache the default value forever.
|
|
||||||
*
|
|
||||||
* @param string $section
|
|
||||||
* @param string $key
|
|
||||||
* @param mixed $default
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function sear_in_section($section, $key, $default)
|
|
||||||
{
|
|
||||||
return $this->sear($this->section_item_key($section, $key), $default);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -140,19 +96,23 @@ public function sear_in_section($section, $key, $default)
|
||||||
*/
|
*/
|
||||||
public function forget($key)
|
public function forget($key)
|
||||||
{
|
{
|
||||||
array_forget($this->storage, $key);
|
if ($this->sectionable($key))
|
||||||
}
|
{
|
||||||
|
list($section, $key) = $this->parse($key);
|
||||||
|
|
||||||
/**
|
if ($key == '*')
|
||||||
* Delete a sectioned item from the cache.
|
{
|
||||||
*
|
$this->forget_section($section);
|
||||||
* @param string $section
|
}
|
||||||
* @param string $key
|
else
|
||||||
* @return void
|
{
|
||||||
*/
|
$this->forget_in_section($section, $key);
|
||||||
public function forget_in_section($section, $key)
|
}
|
||||||
{
|
}
|
||||||
$this->forget($this->section_item_key($section, $key));
|
else
|
||||||
|
{
|
||||||
|
array_forget($this->storage, $key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,6 +2,20 @@
|
||||||
|
|
||||||
abstract class Sectionable extends Driver {
|
abstract class Sectionable extends Driver {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that section caching is implicit based on keys.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $implicit = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The implicit section key delimiter.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $delimiter = '::';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a sectioned item from the cache driver.
|
* Retrieve a sectioned item from the cache driver.
|
||||||
*
|
*
|
||||||
|
@ -10,7 +24,10 @@ abstract class Sectionable extends Driver {
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
abstract public function get_from_section($section, $key, $default = null);
|
public function get_from_section($section, $key, $default = null)
|
||||||
|
{
|
||||||
|
return $this->get($this->section_item_key($section, $key), $default);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a sectioned item to the cache.
|
* Write a sectioned item to the cache.
|
||||||
|
@ -21,7 +38,10 @@ abstract public function get_from_section($section, $key, $default = null);
|
||||||
* @param int $minutes
|
* @param int $minutes
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
abstract public function put_in_section($section, $key, $value, $minutes);
|
public function put_in_section($section, $key, $value, $minutes)
|
||||||
|
{
|
||||||
|
$this->put($this->section_item_key($section, $key), $value, $minutes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a sectioned item to the cache that lasts forever.
|
* Write a sectioned item to the cache that lasts forever.
|
||||||
|
@ -31,7 +51,10 @@ abstract public function put_in_section($section, $key, $value, $minutes);
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
abstract public function forever_in_section($section, $key, $value);
|
public function forever_in_section($section, $key, $value)
|
||||||
|
{
|
||||||
|
return $this->forever($this->section_item_key($section, $key), $value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a sectioned item from the cache, or cache and return the default value.
|
* Get a sectioned item from the cache, or cache and return the default value.
|
||||||
|
@ -42,7 +65,12 @@ abstract public function forever_in_section($section, $key, $value);
|
||||||
* @param int $minutes
|
* @param int $minutes
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
abstract public function remember_in_section($section, $key, $default, $minutes, $function = 'put');
|
public function remember_in_section($section, $key, $default, $minutes, $function = 'put')
|
||||||
|
{
|
||||||
|
$key = $this->section_item_key($section, $key);
|
||||||
|
|
||||||
|
return $this->remember($key, $default, $minutes, $function);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a sectioned item from the cache, or cache the default value forever.
|
* Get a sectioned item from the cache, or cache the default value forever.
|
||||||
|
@ -52,7 +80,10 @@ abstract public function remember_in_section($section, $key, $default, $minutes,
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
abstract public function sear_in_section($section, $key, $default);
|
public function sear_in_section($section, $key, $default)
|
||||||
|
{
|
||||||
|
return $this->sear($this->section_item_key($section, $key), $default);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a sectioned item from the cache.
|
* Delete a sectioned item from the cache.
|
||||||
|
@ -61,7 +92,10 @@ abstract public function sear_in_section($section, $key, $default);
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
abstract public function forget_in_section($section, $key);
|
public function forget_in_section($section, $key)
|
||||||
|
{
|
||||||
|
return $this->forget($this->section_item_key($section, $key));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an entire section from the cache.
|
* Delete an entire section from the cache.
|
||||||
|
|
Loading…
Reference in New Issue