You are here

public function CachePluginBase::cacheSet in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/cache/CachePluginBase.php \Drupal\views\Plugin\views\cache\CachePluginBase::cacheSet()

Save data to the cache.

A plugin should override this to provide specialized caching behavior.

1 method overrides CachePluginBase::cacheSet()
None::cacheSet in core/modules/views/src/Plugin/views/cache/None.php
Replace the cache set logic so it does not set a cache item at all.

File

core/modules/views/src/Plugin/views/cache/CachePluginBase.php, line 106
Contains \Drupal\views\Plugin\views\cache\CachePluginBase.

Class

CachePluginBase
The base plugin to handle caching.

Namespace

Drupal\views\Plugin\views\cache

Code

public function cacheSet($type) {
  switch ($type) {
    case 'query':

      // Not supported currently, but this is certainly where we'd put it.
      break;
    case 'results':
      $data = array(
        'result' => $this
          ->prepareViewResult($this->view->result),
        'total_rows' => isset($this->view->total_rows) ? $this->view->total_rows : 0,
        'current_page' => $this->view
          ->getCurrentPage(),
      );
      $expire = $this
        ->cacheSetMaxAge($type) === Cache::PERMANENT ? Cache::PERMANENT : (int) $this->view
        ->getRequest()->server
        ->get('REQUEST_TIME') + $this
        ->cacheSetMaxAge($type);
      \Drupal::cache($this->resultsBin)
        ->set($this
        ->generateResultsKey(), $data, $expire, $this
        ->getCacheTags());
      break;
  }
}