function CachePluginBase::cacheSet
Same name in other branches
- 8.9.x core/modules/views/src/Plugin/views/cache/CachePluginBase.php \Drupal\views\Plugin\views\cache\CachePluginBase::cacheSet()
- 10 core/modules/views/src/Plugin/views/cache/CachePluginBase.php \Drupal\views\Plugin\views\cache\CachePluginBase::cacheSet()
- 11.x 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 104
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;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.