function CachePluginBase::generateResultsKey

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

Calculates and sets a cache ID used for the result cache.

Return value

string The generated cache ID.

2 calls to CachePluginBase::generateResultsKey()
CachePluginBase::cacheGet in core/modules/views/src/Plugin/views/cache/CachePluginBase.php
Retrieve data from the cache.
CachePluginBase::cacheSet in core/modules/views/src/Plugin/views/cache/CachePluginBase.php
Save data to the cache.

File

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

Class

CachePluginBase
The base plugin to handle caching.

Namespace

Drupal\views\Plugin\views\cache

Code

public function generateResultsKey() {
    if (!isset($this->resultsKey)) {
        $build_info = $this->view->build_info;
        foreach ([
            'query',
            'count_query',
        ] as $index) {
            // If the default query back-end is used generate SQL query strings from
            // the query objects.
            if ($build_info[$index] instanceof SelectInterface) {
                $query = clone $build_info[$index];
                $query->preExecute();
                $build_info[$index] = [
                    'query' => (string) $query,
                    'arguments' => $query->getArguments(),
                ];
            }
        }
        $key_data = [
            'build_info' => $build_info,
        ];
        // @todo https://www.drupal.org/node/2433591 might solve it to not require
        //   the pager information here.
        $key_data['pager'] = [
            'page' => $this->view
                ->getCurrentPage(),
            'items_per_page' => $this->view
                ->getItemsPerPage(),
            'offset' => $this->view
                ->getOffset(),
        ];
        $key_data += \Drupal::service('cache_contexts_manager')->convertTokensToKeys($this->displayHandler
            ->getCacheMetadata()
            ->getCacheContexts())
            ->getKeys();
        $this->resultsKey = $this->view->storage
            ->id() . ':' . $this->displayHandler->display['id'] . ':results:' . hash('sha256', serialize($key_data));
    }
    return $this->resultsKey;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.