class Cache

Implements the cache for a application.

Traits

Strict class for better experience.

Constants

PRIORITY

dependency

EXPIRATION

dependency

EXPIRE

dependency

SLIDING

dependency

TAGS

dependency

FILES

dependency

ITEMS

dependency

CONSTS

dependency

CALLBACKS

dependency

NAMESPACES

dependency

ALL

dependency

NAMESPACE_SEPARATOR

Methods

__construct(IStorage $storage, string $namespace = null)

No description

getStorage()

Returns cache storage.

string
getNamespace()

Returns cache namespace.

derive(string $namespace)

Returns new nested cache object.

mixed
load($key, callable $fallback = null)

Reads the specified item from the cache or generate it.

array
bulkLoad(array $keys, callable $fallback = null)

Reads multiple items from the cache.

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

Writes item into the cache.

void
remove(mixed $key)

Removes item from the cache.

void
clean(array $conditions = null)

Removes items from the cache by conditions.

mixed
call(callable $function)

Caches results of function/method calls.

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

Caches results of function/method calls.

OutputHelper|null
start(mixed $key)

Starts the output cache.

string
generateKey($key)

Generates internal cache key.

static bool
checkCallbacks(array $callbacks)

Checks CALLBACKS dependencies.

Details

at line 46
__construct(IStorage $storage, string $namespace = null)

Parameters

IStorage $storage
string $namespace

at line 56
final IStorage getStorage()

Returns cache storage.

Return Value

IStorage

at line 65
final string getNamespace()

Returns cache namespace.

Return Value

string

at line 75
Cache derive(string $namespace)

Returns new nested cache object.

Parameters

string $namespace

Return Value

Cache

at line 87
mixed load($key, callable $fallback = null)

Reads the specified item from the cache or generate it.

Parameters

$key
callable $fallback

Return Value

mixed

at line 102
array bulkLoad(array $keys, callable $fallback = null)

Reads multiple items from the cache.

Parameters

array $keys
callable $fallback

Return Value

array

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

Writes item into the cache.

Dependencies are: - Cache::PRIORITY => (int) priority - Cache::EXPIRATION => (timestamp) expiration - Cache::SLIDING => (bool) use sliding expiration? - Cache::TAGS => (array) tags - Cache::FILES => (array|string) file names - Cache::ITEMS => (array|string) cache items - Cache::CONSTS => (array|string) cache items

Parameters

$key
$data
array $dependencies

Return Value

mixed value itself

Exceptions

InvalidArgumentException

at line 238
void remove(mixed $key)

Removes item from the cache.

Parameters

mixed $key

Return Value

void

at line 251
void clean(array $conditions = null)

Removes items from the cache by conditions.

Conditions are: - Cache::PRIORITY => (int) priority - Cache::TAGS => (array) tags - Cache::ALL => true

Parameters

array $conditions

Return Value

void

at line 265
mixed call(callable $function)

Caches results of function/method calls.

Parameters

callable $function

Return Value

mixed

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

Caches results of function/method calls.

Parameters

callable $function
array $dependencies

Return Value

Closure

at line 300
OutputHelper|null start(mixed $key)

Starts the output cache.

Parameters

mixed $key

Return Value

OutputHelper|null

at line 314
protected string generateKey($key)

Generates internal cache key.

Parameters

$key

Return Value

string

at line 326
static bool checkCallbacks(array $callbacks)

Checks CALLBACKS dependencies.

Parameters

array $callbacks

Return Value

bool