Same name and namespace in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/cache/CachePluginBase.php \Drupal\views\Plugin\views\cache\CachePluginBase::cacheGet()
  2. 9 core/modules/views/src/Plugin/views/cache/CachePluginBase.php \Drupal\views\Plugin\views\cache\CachePluginBase::cacheGet()

Retrieve data from the cache.

A plugin should override this to provide specialized caching behavior.

Parameters

$type: The cache type, either 'query', 'result'.

Return value

bool TRUE if data has been taken from the cache, otherwise FALSE.

File

core/modules/views/src/Plugin/views/cache/CachePluginBase.php, line 133

Class

CachePluginBase
The base plugin to handle caching.

Namespace

Drupal\views\Plugin\views\cache

Code

public function cacheGet($type) {
  $cutoff = $this
    ->cacheExpire($type);
  switch ($type) {
    case 'query':

      // Not supported currently, but this is certainly where we'd put it.
      return FALSE;
    case 'results':

      // Values to set: $view->result, $view->total_rows, $view->execute_time,
      // $view->current_page.
      if ($cache = \Drupal::cache($this->resultsBin)
        ->get($this
        ->generateResultsKey())) {
        if (!$cutoff || $cache->created > $cutoff) {
          $this->view->result = $cache->data['result'];

          // Load entities for each result.
          $this->view->query
            ->loadEntities($this->view->result);
          $this->view->total_rows = $cache->data['total_rows'];
          $this->view
            ->setCurrentPage($cache->data['current_page']);
          $this->view->execute_time = 0;
          return TRUE;
        }
      }
      return FALSE;
  }
}