public function CachePluginBase::cacheGet

Retrieve data from the cache.

A plugin should override this to provide specialized caching behavior.

1 method overrides CachePluginBase::cacheGet()
None::cacheGet in drupal/core/modules/views/lib/Drupal/views/Plugin/views/cache/None.php
Overrides \Drupal\views\Plugin\views\cache\CachePluginBase::cacheGet().

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php, line 145
Definition of Drupal\views\Plugin\views\cache\CachePluginBase.

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 = cache($this->table)
        ->get($this
        ->generateResultsKey())) {
        if (!$cutoff || $cache->created > $cutoff) {
          $this->view->result = $cache->data['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;
    case 'output':
      if ($cache = cache($this->table)
        ->get($this
        ->generateOutputKey())) {
        if (!$cutoff || $cache->created > $cutoff) {
          $this->storage = $cache->data;
          $this->view->display_handler->output = $cache->data['output'];
          $this
            ->restoreHeaders();
          return TRUE;
        }
      }
      return FALSE;
  }
}