Documentation

ItemInterface extends CacheItemInterface

Augments PSR-6's CacheItemInterface with support for tags and metadata.

Tags
author

Nicolas Grekas p@tchwork.com

Table of Contents

METADATA_CTIME  = 'ctime'
References the time the item took to be created, in milliseconds.
METADATA_EXPIRY  = 'expiry'
References the Unix timestamp stating when the item will expire.
METADATA_TAGS  = 'tags'
References the list of tags that were assigned to the item, as string[].
RESERVED_CHARACTERS  = '{}()/\@:'
Reserved characters that cannot be used in a key or tag.
expiresAfter()  : static
Sets the expiration time for this cache item.
expiresAt()  : static
Sets the expiration time for this cache item.
get()  : mixed
Retrieves the value of the item from the cache associated with this object's key.
getKey()  : string
Returns the key for the current cache item.
getMetadata()  : array<string|int, mixed>
Returns a list of metadata info that were saved alongside with the cached value.
isHit()  : bool
Confirms if the cache item lookup resulted in a cache hit.
set()  : static
Sets the value represented by this cache item.
tag()  : $this
Adds a tag to a cache item.

Constants

METADATA_CTIME

References the time the item took to be created, in milliseconds.

public mixed METADATA_CTIME = 'ctime'

METADATA_EXPIRY

References the Unix timestamp stating when the item will expire.

public mixed METADATA_EXPIRY = 'expiry'

METADATA_TAGS

References the list of tags that were assigned to the item, as string[].

public mixed METADATA_TAGS = 'tags'

RESERVED_CHARACTERS

Reserved characters that cannot be used in a key or tag.

public mixed RESERVED_CHARACTERS = '{}()/\@:'

Methods

expiresAfter()

Sets the expiration time for this cache item.

public expiresAfter(int|DateInterval|null $time) : static
Parameters
$time : int|DateInterval|null
Return values
static

expiresAt()

Sets the expiration time for this cache item.

public expiresAt(DateTimeInterface|null $expiration) : static
Parameters
$expiration : DateTimeInterface|null
Return values
static

get()

Retrieves the value of the item from the cache associated with this object's key.

public get() : mixed

The value returned must be identical to the value originally stored by set().

If isHit() returns false, this method MUST return null. Note that null is a legitimate cached value, so the isHit() method SHOULD be used to differentiate between "null value was found" and "no value was found."

Return values
mixed

getKey()

Returns the key for the current cache item.

public getKey() : string

The key is loaded by the Implementing Library, but should be available to the higher level callers when needed.

Return values
string

getMetadata()

Returns a list of metadata info that were saved alongside with the cached value.

public getMetadata() : array<string|int, mixed>

See ItemInterface::METADATA_* consts for keys potentially found in the returned array.

Return values
array<string|int, mixed>

isHit()

Confirms if the cache item lookup resulted in a cache hit.

public isHit() : bool

Note: This method MUST NOT have a race condition between calling isHit() and calling get().

Return values
bool

set()

Sets the value represented by this cache item.

public set(mixed $value) : static

The $value argument may be any item that can be serialized by PHP, although the method of serialization is left up to the Implementing Library.

Parameters
$value : mixed
Return values
static

tag()

Adds a tag to a cache item.

public tag(string|array<string|int, string> $tags) : $this

Tags are strings that follow the same validation rules as keys.

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

A tag or array of tags

Tags
throws
InvalidArgumentException

When $tag is not valid

throws
CacheException

When the item comes from a pool that is not tag-aware

Return values
$this

Search results