class TwigPhpStorageCache implements CacheInterface (View source)

Provides an alternate cache storage for Twig using PhpStorage.

This class is designed to work on setups with multiple webheads using a local filesystem for the twig cache. When generating the cache key, a hash value depending on the enabled extensions is included. This prevents stale templates from being reused when twig extensions are enabled or disabled.

Constants

SUFFIX_SUBSTRING_LENGTH

The maximum length for each part of the cache key suffix.

Properties

protected CacheBackendInterface $cache

The cache object used for auto-refresh via mtime.

protected PhpStorageInterface $storage

The PhpStorage object used for storing the templates.

protected string $templateCacheFilenamePrefix

The template cache filename prefix.

Methods

__construct(CacheBackendInterface $cache, string $twig_cache_prefix)

Store cache backend and other information internally.

storage()

Gets the PHP code storage object to use for the compiled Twig files.

generateKey($name, $className)

{@inheritdoc}

load($key)

{@inheritdoc}

write($key, $content)

{@inheritdoc}

getTimestamp($key)

{@inheritdoc}

Details

__construct(CacheBackendInterface $cache, string $twig_cache_prefix)

Store cache backend and other information internally.

Parameters

CacheBackendInterface $cache

The cache bin.

string $twig_cache_prefix

A Twig cache file prefix that changes when Twig extensions change.

protected PhpStorageInterface storage()

Gets the PHP code storage object to use for the compiled Twig files.

Return Value

PhpStorageInterface

generateKey($name, $className)

{@inheritdoc}

Parameters

$name
$className

load($key)

{@inheritdoc}

Parameters

$key

write($key, $content)

{@inheritdoc}

Parameters

$key
$content

getTimestamp($key)

{@inheritdoc}

Parameters

$key