CacheItem
in package
implements
ItemInterface
Tags
Table of Contents
Interfaces
- ItemInterface
- Augments PSR-6's CacheItemInterface with support for tags and metadata.
Constants
- METADATA_EXPIRY_OFFSET = 1527506807
- VALUE_WRAPPER = "\xa9"
Properties
- $expiry : float|int|null
- $innerItem : CacheItemInterface|null
- $isHit : bool
- $isTaggable : bool
- $key : string
- $metadata : array<string|int, mixed>
- $newMetadata : array<string|int, mixed>
- $poolHash : string|null
- $value : mixed
Methods
- expiresAfter() : $this
- Sets the expiration time for this cache item.
- expiresAt() : $this
- 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() : $this
- Sets the value represented by this cache item.
- tag() : $this
- Adds a tag to a cache item.
- validateKey() : string
- Validates a cache key according to PSR-6.
- pack() : mixed
- unpack() : bool
Constants
METADATA_EXPIRY_OFFSET
private
mixed
METADATA_EXPIRY_OFFSET
= 1527506807
VALUE_WRAPPER
private
mixed
VALUE_WRAPPER
= "\xa9"
Properties
$expiry
protected
float|int|null
$expiry
= null
$innerItem
protected
CacheItemInterface|null
$innerItem
= null
$isHit
protected
bool
$isHit
= false
$isTaggable
protected
bool
$isTaggable
= false
$key
protected
string
$key
$metadata
protected
array<string|int, mixed>
$metadata
= []
$newMetadata
protected
array<string|int, mixed>
$newMetadata
= []
$poolHash
protected
string|null
$poolHash
= null
$value
protected
mixed
$value
= null
Methods
expiresAfter()
Sets the expiration time for this cache item.
public
expiresAfter(mixed $time) : $this
Parameters
- $time : mixed
-
The period of time from the present after which the item MUST be considered expired. An integer parameter is understood to be the time in seconds until expiration. If null is passed explicitly, a default value MAY be used. If none is set, the value should be stored permanently or for as long as the implementation allows.
Return values
$thisexpiresAt()
Sets the expiration time for this cache item.
public
expiresAt(DateTimeInterface|null $expiration) : $this
Parameters
- $expiration : DateTimeInterface|null
-
The point in time after which the item MUST be considered expired. If null is passed explicitly, a default value MAY be used. If none is set, the value should be stored permanently or for as long as the implementation allows.
Return values
$thisget()
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 —The value corresponding to this cache item's key, or null if not found.
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 —The key string for this cache item.
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 —True if the request resulted in a cache hit. False otherwise.
set()
Sets the value represented by this cache item.
public
set(mixed $value) : $this
Parameters
- $value : mixed
-
The serializable value to be stored.
Return values
$thistag()
Adds a tag to a cache item.
public
tag(mixed $tags) : $this
Tags are strings that follow the same validation rules as keys.
Parameters
- $tags : mixed
-
A tag or array of tags
Return values
$thisvalidateKey()
Validates a cache key according to PSR-6.
public
static validateKey(mixed $key) : string
Parameters
- $key : mixed
-
The key to validate
Tags
Return values
stringpack()
private
pack() : mixed
unpack()
private
unpack() : bool