Documentation

TagAwareAdapter
in package
implements TagAwareAdapterInterface, TagAwareCacheInterface, PruneableInterface, ResettableInterface, LoggerAwareInterface uses ContractsTrait, LoggerAwareTrait

Implements simple and robust tag-based invalidation suitable for use with volatile caches.

This adapter works by storing a version for each tags. When saving an item, it is stored together with its tags and their corresponding versions. When retrieving an item, those tag versions are compared to the current version of each tags. Invalidation is achieved by deleting tags, thereby ensuring that their versions change even when the storage is out of space. When versions of non-existing tags are requested for item commits, this adapter assigns a new random version to them.

Tags
author

Nicolas Grekas p@tchwork.com

author

Sergey Belyshkin sbelyshkin@gmail.com

Table of Contents

Interfaces

TagAwareAdapterInterface
Interface for invalidating cached items using tags.
TagAwareCacheInterface
Allows invalidating cached items using tags.
PruneableInterface
Interface extends psr-6 and psr-16 caches to allow for pruning (deletion) of all expired cache items.
ResettableInterface
Resets a pool's local state.
LoggerAwareInterface
Describes a logger-aware instance.

Constants

TAGS_PREFIX  = "\x01tags\x01"

Properties

$logger  : LoggerInterface|null
The logger instance.
$deferred  : array<string|int, mixed>
$getTagsByKey  : Closure
$knownTagVersions  : array<string|int, mixed>
$knownTagVersionsTtl  : float
$pool  : AdapterInterface
$saveTags  : Closure
$setCacheItemTags  : Closure
$setTagVersions  : Closure
$tags  : AdapterInterface

Methods

__construct()  : mixed
__destruct()  : mixed
__serialize()  : array<string|int, mixed>
__unserialize()  : void
clear()  : bool
Deletes all items in the pool.
commit()  : bool
Persists any deferred cache items.
deleteItem()  : bool
Removes the item from the pool.
deleteItems()  : bool
Removes multiple items from the pool.
getItem()  : CacheItemInterface
Returns a Cache Item representing the specified key.
getItems()  : iterable<string, CacheItem>
Returns a traversable set of cache items.
hasItem()  : bool
Confirms if the cache contains specified cache item.
invalidateTags()  : bool
Invalidates cached items using tags.
prune()  : bool
reset()  : void
save()  : bool
Persists a cache item immediately.
saveDeferred()  : bool
Sets a cache item to be persisted later.
setLogger()  : mixed
Sets a logger.
getTagVersions()  : array<string|int, mixed>

Constants

Properties

$knownTagVersions

private array<string|int, mixed> $knownTagVersions = []

Methods

__serialize()

public __serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

__unserialize()

public __unserialize(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>

clear()

Deletes all items in the pool.

public clear([string $prefix = '' ]) : bool
Parameters
$prefix : string = ''
Return values
bool

True if the pool was successfully cleared. False if there was an error.

commit()

Persists any deferred cache items.

public commit() : bool
Return values
bool

True if all not-yet-saved items were successfully saved or there were none. False otherwise.

deleteItem()

Removes the item from the pool.

public deleteItem(mixed $key) : bool
Parameters
$key : mixed

The key to delete.

Return values
bool

True if the item was successfully removed. False if there was an error.

deleteItems()

Removes multiple items from the pool.

public deleteItems(array<string|int, mixed> $keys) : bool
Parameters
$keys : array<string|int, mixed>

An array of keys that should be removed from the pool.

Return values
bool

True if the items were successfully removed. False if there was an error.

getItem()

Returns a Cache Item representing the specified key.

public getItem(mixed $key) : CacheItemInterface

This method must always return a CacheItemInterface object, even in case of a cache miss. It MUST NOT return null.

Parameters
$key : mixed

The key for which to return the corresponding Cache Item.

Return values
CacheItemInterface

The corresponding Cache Item.

getItems()

Returns a traversable set of cache items.

public getItems([array<string|int, mixed> $keys = [] ]) : iterable<string, CacheItem>
Parameters
$keys : array<string|int, mixed> = []

An indexed array of keys of items to retrieve.

Return values
iterable<string, CacheItem>

hasItem()

Confirms if the cache contains specified cache item.

public hasItem(mixed $key) : bool

Note: This method MAY avoid retrieving the cached value for performance reasons. This could result in a race condition with CacheItemInterface::get(). To avoid such situation use CacheItemInterface::isHit() instead.

Parameters
$key : mixed

The key for which to check existence.

Return values
bool

True if item exists in the cache, false otherwise.

invalidateTags()

Invalidates cached items using tags.

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

An array of tags to invalidate

Return values
bool

saveDeferred()

Sets a cache item to be persisted later.

public saveDeferred(CacheItemInterface $item) : bool
Parameters
$item : CacheItemInterface

The cache item to save.

Return values
bool

False if the item could not be queued or if a commit was attempted and failed. True otherwise.

getTagVersions()

private getTagVersions(array<string|int, mixed> $tagsByKey, bool $persistTags) : array<string|int, mixed>
Parameters
$tagsByKey : array<string|int, mixed>
$persistTags : bool
Return values
array<string|int, mixed>

        
On this page

Search results