SmartTag.php in Tome 8
File
modules/tome_static/modules/tome_static_super_cache/src/Plugin/views/cache/SmartTag.php
View source
<?php
namespace Drupal\tome_static_super_cache\Plugin\views\cache;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\views\Plugin\views\cache\CachePluginBase;
use Drupal\views\ViewExecutable;
class SmartTag extends CachePluginBase {
protected $cache = FALSE;
public function getCacheTags() {
$tags = $this->view->storage
->getCacheTags();
$tags = Cache::mergeTags($tags, $this->view
->getQuery()
->getCacheTags());
$tags = Cache::mergeTags($tags, [
$this
->getTagForView($this->view),
]);
return $tags;
}
public function summaryTitle() {
return $this
->t('Smart tag based');
}
protected function cacheExpire($type) {
return FALSE;
}
protected function getDefaultCacheMaxAge() {
return CacheBackendInterface::CACHE_PERMANENT;
}
public function getTagForView(ViewExecutable $view) {
return implode(':', [
'tome_static_super_cache_smart_tag',
$view
->id(),
$view->current_display,
]);
}
public function disableCache() {
$this->cache = FALSE;
}
public function enableCache() {
$this->cache = TRUE;
}
public function cacheGet($type) {
if ($this->cache) {
return parent::cacheGet($type);
}
return FALSE;
}
public function cacheSet($type) {
if ($this->cache) {
parent::cacheSet($type);
}
}
}
Classes
Name |
Description |
SmartTag |
Omits list cache tags from a View and expires cache on entity CRUD. |