Cecil

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

$builder  : Builder
$cacheDir  : string

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

$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
bool

clearByPattern()

Clear cache by pattern.

public clearByPattern(string $pattern) : int
Parameters
$pattern : string
Return values
int

createKey()

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
throws
InvalidArgumentException

if the $value type is not supported or if the generated key contains reserved characters.

Return values
string

delete()

{@inheritdoc}

public delete(mixed $key) : bool
Parameters
$key : mixed
Return values
bool

deleteMultiple()

{@inheritdoc}

public deleteMultiple(mixed $keys) : bool
Parameters
$keys : mixed
Return values
bool

get()

{@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
string

getMultiple()

{@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
bool

set()

{@inheritdoc}

public set(mixed $key, mixed $value[, mixed $ttl = null ]) : bool
Parameters
$key : mixed
$value : mixed
$ttl : mixed = null
Return values
bool

setMultiple()

{@inheritdoc}

public setMultiple(mixed $values[, mixed $ttl = null ]) : bool
Parameters
$values : mixed
$ttl : mixed = null
Return values
bool

deleteContentFile()

Removes the cache content file.

protected deleteContentFile(string $path) : bool
Parameters
$path : string
Return values
bool

duration()

Convert the various expressions of a TTL value into duration in seconds.

protected duration(int|DateInterval $ttl) : int
Parameters
$ttl : int|DateInterval
Return values
int

getFile()

Returns cache file from key.

private getFile(string $key) : string
Parameters
$key : string
Return values
string

prune()

Removes previous cache files.

private prune(string $key) : bool
Parameters
$key : string
Return values
bool

sanitizeKey()

Prepares and validate $key.

private static sanitizeKey(string $key) : string
Parameters
$key : string
Tags
throws
InvalidArgumentException

if the $key contains reserved characters.

Return values
string
 
On this page

Search results