public function CachePluginBase::cacheSet in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/cache/CachePluginBase.php \Drupal\views\Plugin\views\cache\CachePluginBase::cacheSet()
- 9 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.
Parameters
$type: The cache type, either 'query', 'result'.
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 105
Class
- CachePluginBase
- The base plugin to handle caching.
Namespace
Drupal\views\Plugin\views\cacheCode
public function cacheSet($type) {
switch ($type) {
case 'query':
// Not supported currently, but this is certainly where we'd put it.
break;
case 'results':
$data = [
'result' => $this
->prepareViewResult($this->view->result),
'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;
}
}