More work on sectionable caches.

This commit is contained in:
Taylor Otwell 2012-04-28 22:46:25 -05:00
parent 31106a9211
commit aaeb7bc3be
3 changed files with 43 additions and 43 deletions

View File

@ -1,6 +1,6 @@
<?php namespace Laravel\Cache\Drivers;
class Memcached extends Driver implements Sectionable {
class Memcached extends Sectionable {
/**
* The Memcache instance.
@ -277,37 +277,4 @@ protected function section_item_key($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.
*
* @param string $key
* @return bool
*/
protected function sectioned($key)
{
return str_contains($key, '::');
}
/**
* Get the section and key from a sectioned key.
*
* @param string $key
* @return array
*/
protected function parse($key)
{
return explode('::', $key, 2);
}
}

View File

@ -1,6 +1,6 @@
<?php namespace Laravel\Cache\Drivers;
class Memory extends Driver implements Sectionable {
class Memory extends Sectionable {
/**
* The in-memory array of cached items.

View File

@ -1,6 +1,6 @@
<?php namespace Laravel\Cache\Drivers;
interface Sectionable {
abstract class Sectionable extends Driver {
/**
* Retrieve a sectioned item from the cache driver.
@ -10,7 +10,7 @@ interface Sectionable {
* @param mixed $default
* @return mixed
*/
public function get_from_section($section, $key, $default = null);
abstract public function get_from_section($section, $key, $default = null);
/**
* Write a sectioned item to the cache.
@ -21,7 +21,7 @@ public function get_from_section($section, $key, $default = null);
* @param int $minutes
* @return void
*/
public function put_in_section($section, $key, $value, $minutes);
abstract public function put_in_section($section, $key, $value, $minutes);
/**
* Write a sectioned item to the cache that lasts forever.
@ -31,7 +31,7 @@ public function put_in_section($section, $key, $value, $minutes);
* @param mixed $value
* @return void
*/
public function forever_in_section($section, $key, $value);
abstract public function forever_in_section($section, $key, $value);
/**
* Get a sectioned item from the cache, or cache and return the default value.
@ -42,7 +42,7 @@ public function forever_in_section($section, $key, $value);
* @param int $minutes
* @return mixed
*/
public function remember_in_section($section, $key, $default, $minutes, $function = 'put');
abstract public function remember_in_section($section, $key, $default, $minutes, $function = 'put');
/**
* Get a sectioned item from the cache, or cache the default value forever.
@ -52,7 +52,7 @@ public function remember_in_section($section, $key, $default, $minutes, $functio
* @param mixed $default
* @return mixed
*/
public function sear_in_section($section, $key, $default);
abstract public function sear_in_section($section, $key, $default);
/**
* Delete a sectioned item from the cache.
@ -61,7 +61,7 @@ public function sear_in_section($section, $key, $default);
* @param string $key
* @return void
*/
public function forget_in_section($section, $key);
abstract public function forget_in_section($section, $key);
/**
* Delete an entire section from the cache.
@ -69,6 +69,39 @@ public function forget_in_section($section, $key);
* @param string $section
* @return int|bool
*/
public function forget_section($section);
abstract public function forget_section($section);
/**
* 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.
*
* @param string $key
* @return bool
*/
protected function sectioned($key)
{
return str_contains($key, '::');
}
/**
* Get the section and key from a sectioned key.
*
* @param string $key
* @return array
*/
protected function parse($key)
{
return explode('::', $key, 2);
}
}