class Cache

Implements the cache for a application.

Constants

Priority

dependency

Expire

dependency

Sliding

dependency

Tags

dependency

Files

dependency

Items

dependency

Constants

dependency

Callbacks

dependency

Namespaces

dependency

All

dependency

PRIORITY

EXPIRATION

EXPIRE

SLIDING

TAGS

FILES

ITEMS

CONSTS

CALLBACKS

NAMESPACES

ALL

internal NamespaceSeparator

Methods

__construct(Storage $storage, string|null $namespace = null)

No description

getStorage()

Returns cache storage.

string
getNamespace()

Returns cache namespace.

derive(string $namespace)

Returns new nested cache object.

mixed
load(mixed $key, callable|null $generator = null, array|null $dependencies = null)

Reads the specified item from the cache or generate it.

array
bulkLoad(array $keys, callable|null $generator = null)

Reads multiple items from the cache.

mixed
save(mixed $key, mixed $data, array|null $dependencies = null)

Writes item into the cache.

void
bulkSave(array $items, array|null $dependencies = null)

Writes multiple items into cache

void
remove(mixed $key)

Removes item from the cache.

void
clean(array|null $conditions = null)

Removes items from the cache by conditions.

mixed
call(callable $function)

Caches results of function/method calls.

wrap(callable $function, array|null $dependencies = null)

Caches results of function/method calls.

OutputHelper|null
capture(mixed $key)

Starts the output cache.

OutputHelper|null
start($key)

No description

string
generateKey($key)

Generates internal cache key.

static bool
checkCallbacks(array $callbacks)

Checks CALLBACKS dependencies.

Details

at line 73
__construct(Storage $storage, string|null $namespace = null)

No description

Parameters

Storage $storage
string|null $namespace

at line 83
final Storage getStorage()

Returns cache storage.

Return Value

Storage

at line 92
final string getNamespace()

Returns cache namespace.

Return Value

string

at line 101
Cache derive(string $namespace)

Returns new nested cache object.

Parameters

string $namespace

Return Value

Cache

at line 110
mixed load(mixed $key, callable|null $generator = null, array|null $dependencies = null)

Reads the specified item from the cache or generate it.

Parameters

mixed $key
callable|null $generator
array|null $dependencies

Return Value

mixed

at line 133
array bulkLoad(array $keys, callable|null $generator = null)

Reads multiple items from the cache.

Parameters

array $keys
callable|null $generator

Return Value

array

at line 189
mixed save(mixed $key, mixed $data, array|null $dependencies = null)

Writes item into the cache.

Dependencies are:

  • Cache::Priority => (int) priority
  • Cache::Expire => (timestamp) expiration, infinite if null
  • Cache::Sliding => (bool) use sliding expiration?
  • Cache::Tags => (array) tags
  • Cache::Files => (array|string) file names
  • Cache::Items => (array|string) cache items
  • Cache::Constants => (array|string) cache items

Parameters

mixed $key
mixed $data
array|null $dependencies

Return Value

mixed

value itself

Exceptions

InvalidArgumentException

at line 222
void bulkSave(array $items, array|null $dependencies = null)

Writes multiple items into cache

Parameters

array $items
array|null $dependencies

Return Value

void

at line 309
void remove(mixed $key)

Removes item from the cache.

Parameters

mixed $key

Return Value

void

at line 322
void clean(array|null $conditions = null)

Removes items from the cache by conditions.

Conditions are:

  • Cache::Priority => (int) priority
  • Cache::Tags => (array) tags
  • Cache::All => true

Parameters

array|null $conditions

Return Value

void

at line 336
mixed call(callable $function)

Caches results of function/method calls.

Parameters

callable $function

Return Value

mixed

at line 350
Closure wrap(callable $function, array|null $dependencies = null)

Caches results of function/method calls.

Parameters

callable $function
array|null $dependencies

Return Value

Closure

at line 369
OutputHelper|null capture(mixed $key)

Starts the output cache.

Parameters

mixed $key

Return Value

OutputHelper|null

at line 381
OutputHelper|null start($key)

No description

Parameters

$key

Return Value

OutputHelper|null

at line 392
protected string generateKey($key)

Generates internal cache key.

Parameters

$key

Return Value

string

at line 404
static bool checkCallbacks(array $callbacks)

Checks CALLBACKS dependencies.

Parameters

array $callbacks

Return Value

bool