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.

string
generateKey(string $name, string $className)

{@inheritdoc}

void
load(string $key)

{@inheritdoc}

void
write(string $key, string $content)

{@inheritdoc}

int
getTimestamp(string $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

string generateKey(string $name, string $className)

{@inheritdoc}

Parameters

string $name
string $className

Return Value

string

void load(string $key)

{@inheritdoc}

Parameters

string $key

Return Value

void

void write(string $key, string $content)

{@inheritdoc}

Parameters

string $key
string $content

Return Value

void

int getTimestamp(string $key)

{@inheritdoc}

Parameters

string $key

Return Value

int