CacheItem
in package
implements
CacheItemInterface
Interfaces, Classes, Traits and Enums
- CacheItemInterface
- CacheItemInterface defines an interface for interacting with objects inside a cache.
Table of Contents
- $expiration : int|null
- Timestamp item will expire at if expiresAt() called, null otherwise
- $isHit : bool
- True if the cache item lookup resulted in a cache hit or if they item is deferred or successfully saved
- $key : string
- Cache key
- $ttl : int|null
- Seconds after item is stored it will expire at if expiresAfter() called, null otherwise
- $tz : DateTimeZone
- $value : mixed|null
- Cache value
- __construct() : mixed
- Constructor.
- 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.
- getTtl() : int|null
- Returns number of seconds until item expires
- isHit() : bool
- Confirms if the cache item lookup resulted in a cache hit.
- set() : static
- Sets the value represented by this cache item.
- setIsHit() : $this
- Sets isHit value
Properties
$expiration
Timestamp item will expire at if expiresAt() called, null otherwise
private
int|null
$expiration
= null
$isHit
True if the cache item lookup resulted in a cache hit or if they item is deferred or successfully saved
private
bool
$isHit
= false
$key
Cache key
private
string
$key
$ttl
Seconds after item is stored it will expire at if expiresAfter() called, null otherwise
private
int|null
$ttl
= null
$tz
private
DateTimeZone
$tz
$value
Cache value
private
mixed|null
$value
Methods
__construct()
Constructor.
public
__construct(string $key, mixed $value, bool $isHit) : mixed
Parameters
- $key : string
- $value : mixed
- $isHit : bool
Return values
mixed —expiresAfter()
Sets the expiration time for this cache item.
public
expiresAfter(mixed $time) : static
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
static —The called object.
expiresAt()
Sets the expiration time for this cache item.
public
expiresAt(mixed $expiration) : static
Parameters
- $expiration : mixed
-
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
static —The called object.
get()
Retrieves the value of the item from the cache associated with this object's key.
public
get() : mixed
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
Return values
string —The key string for this cache item.
getTtl()
Returns number of seconds until item expires
public
getTtl() : int|null
If NULL, the pool should use the default TTL for the storage adapter. If <= 0, the item has expired.
Return values
int|null —isHit()
Confirms if the cache item lookup resulted in a cache hit.
public
isHit() : bool
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) : static
Parameters
- $value : mixed
-
The serializable value to be stored.
Return values
static —The invoked object.
setIsHit()
Sets isHit value
public
setIsHit(bool $isHit) : $this
This function is called by CacheItemPoolDecorator::saveDeferred() and is not intended for use by other calling code.
Parameters
- $isHit : bool