abstract class SimplenewsSourceCacheStatic in Simplenews 7
Same name and namespace in other branches
- 7.2 includes/simplenews.source.inc \SimplenewsSourceCacheStatic
Abstract implementation of the source caching that does static caching.
Subclasses need to implement the abstract function isCacheable() to decide what should be cached.
Hierarchy
- class \SimplenewsSourceCacheStatic implements SimplenewsSourceCacheInterface
Expanded class hierarchy of SimplenewsSourceCacheStatic
Related topics
File
- includes/
simplenews.source.inc, line 844 - Contains SimplenewsSource interface and implementations.
View source
abstract class SimplenewsSourceCacheStatic implements SimplenewsSourceCacheInterface {
/**
* The simplenews source for which this cache is used.
*
* @var SimplenewsSourceNodeInterface
*/
protected $source;
/**
* The cache identifier for the given source.
*/
protected $cid;
/**
* The static cache.
*/
protected static $cache = array();
/**
* Implements SimplenewsSourceNodeInterface::__construct().
*/
public function __construct(SimplenewsSourceNodeInterface $source) {
$this->source = $source;
self::$cache =& drupal_static(__CLASS__, array());
}
/**
* Returns the cache identifier for the current source.
*/
protected function getCid() {
if (empty($this->cid)) {
$this->cid = $this->source
->getNode()->nid . ':' . $this->source
->getLanguage();
}
return $this->cid;
}
/**
* Implements SimplenewsSourceNodeInterface::get().
*/
public function get($group, $key) {
if (!$this
->isCacheable($group, $key)) {
return;
}
if (isset(self::$cache[$this
->getCid()][$group][$key])) {
return self::$cache[$this
->getCid()][$group][$key];
}
}
/**
* Implements SimplenewsSourceNodeInterface::set().
*/
public function set($group, $key, $data) {
if (!$this
->isCacheable($group, $key)) {
return;
}
self::$cache[$this
->getCid()][$group][$key] = $data;
}
/**
* Return if the requested element should be cached.
*
* @return
* TRUE if it should be cached, FALSE otherwise.
*/
abstract function isCacheable($group, $key);
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SimplenewsSourceCacheStatic:: |
protected static | property | The static cache. | |
SimplenewsSourceCacheStatic:: |
protected | property | The cache identifier for the given source. | |
SimplenewsSourceCacheStatic:: |
protected | property | The simplenews source for which this cache is used. | |
SimplenewsSourceCacheStatic:: |
public | function |
Implements SimplenewsSourceNodeInterface::get(). Overrides SimplenewsSourceCacheInterface:: |
|
SimplenewsSourceCacheStatic:: |
protected | function | Returns the cache identifier for the current source. | |
SimplenewsSourceCacheStatic:: |
abstract | function | Return if the requested element should be cached. | 2 |
SimplenewsSourceCacheStatic:: |
public | function |
Implements SimplenewsSourceNodeInterface::set(). Overrides SimplenewsSourceCacheInterface:: |
|
SimplenewsSourceCacheStatic:: |
public | function |
Implements SimplenewsSourceNodeInterface::__construct(). Overrides SimplenewsSourceCacheInterface:: |