You are here

abstract class SimplenewsSourceCacheStatic in Simplenews 7

Same name and namespace in other branches
  1. 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

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

Namesort descending Modifiers Type Description Overrides
SimplenewsSourceCacheStatic::$cache protected static property The static cache.
SimplenewsSourceCacheStatic::$cid protected property The cache identifier for the given source.
SimplenewsSourceCacheStatic::$source protected property The simplenews source for which this cache is used.
SimplenewsSourceCacheStatic::get public function Implements SimplenewsSourceNodeInterface::get(). Overrides SimplenewsSourceCacheInterface::get
SimplenewsSourceCacheStatic::getCid protected function Returns the cache identifier for the current source.
SimplenewsSourceCacheStatic::isCacheable abstract function Return if the requested element should be cached. 2
SimplenewsSourceCacheStatic::set public function Implements SimplenewsSourceNodeInterface::set(). Overrides SimplenewsSourceCacheInterface::set
SimplenewsSourceCacheStatic::__construct public function Implements SimplenewsSourceNodeInterface::__construct(). Overrides SimplenewsSourceCacheInterface::__construct