You are here

class CacheBackendDecorator in Multiversion 8

Hierarchy

Expanded class hierarchy of CacheBackendDecorator

File

src/CacheBackendDecorator.php, line 8

Namespace

Drupal\multiversion
View source
class CacheBackendDecorator implements CacheBackendInterface {

  /**
   * @var \Drupal\Core\Cache\CacheBackendInterface
   */
  protected $decorated;

  /**
   * @var \Drupal\multiversion\Workspace\WorkspaceManagerInterface
   */
  protected $workspaceManager;

  /**
   * Constructor
   *
   * @param \Drupal\Core\Cache\CacheBackendInterface $decorated
   * @param \Drupal\multiversion\Workspace\WorkspaceManagerInterface $workspace_manager
   */
  public function __construct(CacheBackendInterface $decorated, WorkspaceManagerInterface $workspace_manager) {
    $this->decorated = $decorated;
    $this->workspaceManager = $workspace_manager;
  }

  /**
   * Helper method to decorate a cache ID.
   *
   * @param string $cid
   * @return string
   */
  protected function decorate($cid) {
    return "{$cid}:" . $this->workspaceManager
      ->getActiveWorkspaceId();
  }

  /**
   * {@inheritdoc}
   */
  public function get($cid, $allow_invalid = FALSE) {
    $cid = $this
      ->decorate($cid);
    return $this->decorated
      ->get($cid, $allow_invalid);
  }

  /**
   * {@inheritdoc}
   */
  public function getMultiple(&$cids, $allow_invalid = FALSE) {
    foreach ($cids as &$cid) {
      $cid = $this
        ->decorate($cid);
    }
    return $this->decorated
      ->getMultiple($cids, $allow_invalid);
  }

  /**
   * {@inheritdoc}
   */
  public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
    $cid = $this
      ->decorate($cid);
    return $this->decorated
      ->set($cid, $data, $expire, $tags);
  }

  /**
   * {@inheritdoc}
   */
  public function setMultiple(array $items) {
    $decorated_items = [];
    foreach ($items as $cid => $item) {
      $decorated_items[$this
        ->decorate($cid)] = $item;

      // Save some memory.
      unset($items[$cid]);
    }
    return $this
      ->setMultiple($decorated_items);
  }

  /**
   * {@inheritdoc}
   */
  public function delete($cid) {
    $cid = $this
      ->decorate($cid);
    return $this
      ->delete($cid);
  }

  /**
   * {@inheritdoc}
   */
  public function deleteMultiple(array $cids) {
    foreach ($cids as &$cid) {
      $cid = $this
        ->decorate($cid);
    }
    return $this->decorated
      ->deleteMultiple($cids);
  }

  /**
   * {@inheritdoc}
   */
  public function deleteAll() {
    return $this->decorated
      ->deleteAll();
  }

  /**
   * {@inheritdoc}
   */
  public function invalidate($cid) {
    $cid = $this
      ->decorate($cid);
    return $this->decorated
      ->invalidate($cid);
  }

  /**
   * {@inheritdoc}
   */
  public function invalidateMultiple(array $cids) {
    foreach ($cids as &$cid) {
      $cid = $this
        ->decorate($cid);
    }
    return $this->decorated
      ->invalidateMultiple($cids);
  }

  /**
   * {@inheritdoc}
   */
  public function invalidateAll() {
    return $this->decorated
      ->invalidateAll();
  }

  /**
   * {@inheritdoc}
   */
  public function garbageCollection() {
    return $this->decorated
      ->garbageCollection();
  }

  /**
   * {@inheritdoc}
   */
  public function removeBin() {
    return $this->decorated
      ->removeBin();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheBackendDecorator::$decorated protected property
CacheBackendDecorator::$workspaceManager protected property
CacheBackendDecorator::decorate protected function Helper method to decorate a cache ID.
CacheBackendDecorator::delete public function Deletes an item from the cache. Overrides CacheBackendInterface::delete
CacheBackendDecorator::deleteAll public function Deletes all cache items in a bin. Overrides CacheBackendInterface::deleteAll
CacheBackendDecorator::deleteMultiple public function Deletes multiple items from the cache. Overrides CacheBackendInterface::deleteMultiple
CacheBackendDecorator::garbageCollection public function Performs garbage collection on a cache bin. Overrides CacheBackendInterface::garbageCollection
CacheBackendDecorator::get public function Returns data from the persistent cache. Overrides CacheBackendInterface::get
CacheBackendDecorator::getMultiple public function Returns data from the persistent cache when given an array of cache IDs. Overrides CacheBackendInterface::getMultiple
CacheBackendDecorator::invalidate public function Marks a cache item as invalid. Overrides CacheBackendInterface::invalidate
CacheBackendDecorator::invalidateAll public function Marks all cache items as invalid. Overrides CacheBackendInterface::invalidateAll
CacheBackendDecorator::invalidateMultiple public function Marks cache items as invalid. Overrides CacheBackendInterface::invalidateMultiple
CacheBackendDecorator::removeBin public function Remove a cache bin. Overrides CacheBackendInterface::removeBin
CacheBackendDecorator::set public function Stores data in the persistent cache. Overrides CacheBackendInterface::set
CacheBackendDecorator::setMultiple public function Store multiple items in the persistent cache. Overrides CacheBackendInterface::setMultiple
CacheBackendDecorator::__construct public function Constructor
CacheBackendInterface::CACHE_PERMANENT constant Indicates that the item should never be removed unless explicitly deleted.