Add RemovableCacheInterface

This commit is contained in:
Fabien Potencier
2024-09-25 08:07:40 +02:00
parent efc527ea65
commit 786a67b1a9
6 changed files with 55 additions and 3 deletions
+10
View File
@@ -14,6 +14,7 @@ namespace Twig;
use Twig\Cache\CacheInterface;
use Twig\Cache\FilesystemCache;
use Twig\Cache\NullCache;
use Twig\Cache\RemovableCacheInterface;
use Twig\Error\Error;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
@@ -233,6 +234,15 @@ class Environment
return $this->strictVariables;
}
public function removeCache(string $name): void
{
if ($this->cache instanceof RemovableCacheInterface) {
$this->cache->remove($name, $this->getTemplateClass($name));
} else {
throw new \LogicException(\sprintf('The "%s" cache class does not support removing template cache as it does not implement the "RemovableCacheInterface" interface.', \get_class($this->cache)));
}
}
/**
* Gets the current cache implementation.
*