Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CachePluginBase.php

function 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.

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

File

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

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;
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal