Cache implements CacheInterface
Cache class. Provides methods to manage cache files for assets, pages, and other data.
Table of Contents
Interfaces
- CacheInterface
Constants
- RESERVED_CHARACTERS = '{}()/\@:'
- Reserved characters that cannot be used in a key
Properties
Methods
- __construct() : mixed
- clear() : bool
- {@inheritdoc}
- clearByPattern() : int
- Clear cache by pattern.
- createKey() : string
- Creates key: "$name_$tags__HASH__VERSION".
- delete() : bool
- {@inheritdoc}
- deleteMultiple() : bool
- {@inheritdoc}
- get() : mixed
- {@inheritdoc}
- getContentFile() : string
- Returns cache content file from path.
- getMultiple() : iterable<string|int, mixed>
- {@inheritdoc}
- has() : bool
- {@inheritdoc}
- set() : bool
- {@inheritdoc}
- setMultiple() : bool
- {@inheritdoc}
- deleteContentFile() : bool
- Removes the cache content file.
- duration() : int
- Convert the various expressions of a TTL value into duration in seconds.
- getFile() : string
- Returns cache file from key.
- prune() : bool
- Removes previous cache files.
- sanitizeKey() : string
- Prepares and validate $key.
Constants
RESERVED_CHARACTERS
Reserved characters that cannot be used in a key
public
mixed
RESERVED_CHARACTERS
= '{}()/\@:'
Properties
$builder
protected
Builder
$builder
$cacheDir
protected
string
$cacheDir
Methods
__construct()
public
__construct(Builder $builder[, string $pool = '' ]) : mixed
Parameters
- $builder : Builder
- $pool : string = ''
clear()
{@inheritdoc}
public
clear() : bool
Return values
boolclearByPattern()
Clear cache by pattern.
public
clearByPattern(string $pattern) : int
Parameters
- $pattern : string
Return values
intcreateKey()
Creates key: "$name_$tags__HASH__VERSION".
public
createKey(mixed $value[, string|null $name = null ][, array<string|int, mixed>|null $tags = null ]) : string
The $name is generated from the $value (string, Asset, or file) and can be customized with the $name parameter. The $tags are generated from the $tags parameter and can be used to add extra information to the key (e.g., options used to process the value). They are optional and can be empty. The $hash is generated from the $value and is used to identify the content. It is generated with a fast non-cryptographic hash function (xxh128) to ensure good performance. The $version is the Cecil version, used to invalidate cache when Cecil is updated. The key is sanitized to remove reserved characters and ensure it is a valid file name. It is also truncated to 200 characters to avoid issues with file system limits.
Parameters
- $value : mixed
- $name : string|null = null
- $tags : array<string|int, mixed>|null = null
Tags
Return values
stringdelete()
{@inheritdoc}
public
delete(mixed $key) : bool
Parameters
- $key : mixed
Return values
booldeleteMultiple()
{@inheritdoc}
public
deleteMultiple(mixed $keys) : bool
Parameters
- $keys : mixed
Return values
boolget()
{@inheritdoc}
public
get(mixed $key[, mixed $default = null ]) : mixed
Parameters
- $key : mixed
- $default : mixed = null
getContentFile()
Returns cache content file from path.
public
getContentFile(string $path) : string
Parameters
- $path : string
Return values
stringgetMultiple()
{@inheritdoc}
public
getMultiple(mixed $keys[, mixed $default = null ]) : iterable<string|int, mixed>
Parameters
- $keys : mixed
- $default : mixed = null
Return values
iterable<string|int, mixed>has()
{@inheritdoc}
public
has(mixed $key) : bool
Parameters
- $key : mixed
Return values
boolset()
{@inheritdoc}
public
set(mixed $key, mixed $value[, mixed $ttl = null ]) : bool
Parameters
- $key : mixed
- $value : mixed
- $ttl : mixed = null
Return values
boolsetMultiple()
{@inheritdoc}
public
setMultiple(mixed $values[, mixed $ttl = null ]) : bool
Parameters
- $values : mixed
- $ttl : mixed = null
Return values
booldeleteContentFile()
Removes the cache content file.
protected
deleteContentFile(string $path) : bool
Parameters
- $path : string
Return values
boolduration()
Convert the various expressions of a TTL value into duration in seconds.
protected
duration(int|DateInterval $ttl) : int
Parameters
- $ttl : int|DateInterval
Return values
intgetFile()
Returns cache file from key.
private
getFile(string $key) : string
Parameters
- $key : string
Return values
stringprune()
Removes previous cache files.
private
prune(string $key) : bool
Parameters
- $key : string
Return values
boolsanitizeKey()
Prepares and validate $key.
private
static sanitizeKey(string $key) : string
Parameters
- $key : string