Documentation

TagAwareCacheInterface extends CacheInterface

Allows invalidating cached items using tags.

Tags
author

Nicolas Grekas p@tchwork.com

Table of Contents

delete()  : bool
Removes an item from the pool.
get()  : mixed
Fetches a value from the pool or computes it if not found.
invalidateTags()  : bool
Invalidates cached items using tags.

Methods

delete()

Removes an item from the pool.

public delete(string $key) : bool
Parameters
$key : string

The key to delete

Tags
throws
InvalidArgumentException

When $key is not valid

Return values
bool

True if the item was successfully removed, false if there was any error

get()

Fetches a value from the pool or computes it if not found.

public get(string $key, callable|CallbackInterface $callback[, float|null $beta = null ][, array<string|int, mixed> &$metadata = null ]) : mixed

On cache misses, a callback is called that should return the missing value. This callback is given a PSR-6 CacheItemInterface instance corresponding to the requested key, that could be used e.g. for expiration control. It could also be an ItemInterface instance when its additional features are needed.

Parameters
$key : string

The key of the item to retrieve from the cache

$callback : callable|CallbackInterface

Should return the computed value for the given key/item

$beta : float|null = null

A float that, as it grows, controls the likeliness of triggering early expiration. 0 disables it, INF forces immediate expiration. The default (or providing null) is implementation dependent but should typically be 1.0, which should provide optimal stampede protection. See https://en.wikipedia.org/wiki/Cache_stampede#Probabilistic_early_expiration

$metadata : array<string|int, mixed> = null

The metadata of the cached item ItemInterface::getMetadata()

Tags
throws
InvalidArgumentException

When $key is not valid or when $beta is negative

Return values
mixed

invalidateTags()

Invalidates cached items using tags.

public invalidateTags(array<string|int, string> $tags) : bool

When implemented on a PSR-6 pool, invalidation should not apply to deferred items. Instead, they should be committed as usual. This allows replacing old tagged values by new ones without race conditions.

Parameters
$tags : array<string|int, string>

An array of tags to invalidate

Tags
throws
InvalidArgumentException

When $tags is not valid

Return values
bool

True on success

Search results