Skip to content
Snippets Groups Projects

#3463657 "Add service tags"

Closed Saurav Kumar requested to merge issue/drupal-3463657:3463657-add-service-tags into 11.x
12 files
+ 216
0
Compare changes
  • Side-by-side
  • Inline
Files
12
<?php
namespace Drupal\drupal_cache_clear\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
class CustomCacheClearer {
protected $defaultCache;
protected $customCache;
public function __construct(CacheBackendInterface $defaultCache, CacheBackendInterface $customCache) {
$this->defaultCache = $defaultCache;
$this->customCache = $customCache;
}
/**
* Clears cache based on tags.
*
* @param array $tags
* An array of cache tags to invalidate. If empty, clears all cache.
*/
public function clear($tags = []) {
if (empty($tags)) {
// Clear all caches if no tags are provided.
$this->defaultCache->deleteAll();
$this->customCache->deleteAll();
}
else {
// Clear caches for specific tags.
$this->defaultCache->invalidateTags($tags);
$this->customCache->invalidateTags($tags);
}
}
}
Loading