You are here

class RestfulStaticCacheController in RESTful 7

@file Contains RestfulStaticCacheController

Hierarchy

Expanded class hierarchy of RestfulStaticCacheController

File

includes/RestfulStaticCacheController.php, line 8
Contains RestfulStaticCacheController

View source
class RestfulStaticCacheController implements \RestfulStaticCacheControllerInterface {

  /**
   * @var array
   *
   * The cache ID registry.
   */
  protected $cids = array();

  /**
   * @var string
   *
   * The cache key prefix.
   */
  protected $prefix;

  /**
   * Constructor
   */
  public function __construct() {
    $this->prefix = 'restful_' . mt_rand() . '_';
  }

  /**
   * {@inheritdoc}
   */
  public function get($cid, $default = NULL) {
    $this
      ->registerCid($cid);
    return drupal_static($this->prefix . $cid, $default);
  }

  /**
   * {@inheritdoc}
   */
  public function set($cid, $value) {
    $val =& drupal_static($this->prefix . $cid);
    $val = $value;
  }

  /**
   * {@inheritdoc}
   */
  public function clear($cid) {
    drupal_static_reset($this->prefix . $cid);
  }

  /**
   * {@inheritdoc}
   */
  public function clearAll() {
    foreach ($this
      ->getCids() as $cid) {
      $this
        ->clear($cid);
    }
  }

  /**
   * Register cache ID. The registry is used by clearAll.
   *
   * @param string $cid
   *   The cache ID to register.
   */
  protected function registerCid($cid) {
    if (!in_array($cid, $this->cids)) {
      $this->cids[] = $cid;
    }
  }

  /**
   * Cache ID accessor.
   *
   * @return array
   *   The cache IDs.
   */
  public function getCids() {
    return $this->cids;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RestfulStaticCacheController::$cids protected property The cache ID registry.
RestfulStaticCacheController::$prefix protected property The cache key prefix.
RestfulStaticCacheController::clear public function Clear a particular cache value. Overrides RestfulStaticCacheControllerInterface::clear
RestfulStaticCacheController::clearAll public function Clear all registered cache values. Overrides RestfulStaticCacheControllerInterface::clearAll
RestfulStaticCacheController::get public function Gets the static cache. Overrides RestfulStaticCacheControllerInterface::get
RestfulStaticCacheController::getCids public function Cache ID accessor.
RestfulStaticCacheController::registerCid protected function Register cache ID. The registry is used by clearAll.
RestfulStaticCacheController::set public function Sets the static cache. Overrides RestfulStaticCacheControllerInterface::set
RestfulStaticCacheController::__construct public function Constructor