final class CacheItem implements CacheItemInterface (View source)

Holds one PSR-6 cache value together with its original hit state and optional expiration.

Value and expiration are mutable as required by PSR-6, while key and hit origin remain fixed.

Methods

__construct(string $key, mixed $value = null, bool $hit = false, DateTimeImmutable|null $expiresAt = null)

Captures the key, value, lookup result, and optional absolute expiration.

string
getKey()

Returns the immutable key associated with this item.

string
mixed
get()

Returns the value currently held by this item.

mixed
bool
isHit()

Reports a hit only when the item originated as one and has not expired.

bool
set(mixed $value)

Replaces the held value and returns this item for fluent mutation.

expiresAt(DateTimeInterface|null $expiration)

Sets an absolute expiration using an immutable copy, or clears it with null.

expiresAfter(DateInterval|int|null $time)

Sets expiration relative to now, clamps negative seconds to zero, or clears it with null.

Exposes the normalized absolute expiration used by framework pool implementations.

Details

__construct

__construct(string $key, mixed $value = null, bool $hit = false, DateTimeImmutable|null $expiresAt = null)

Captures the key, value, lookup result, and optional absolute expiration.

Parameters

string $key
mixed $value
bool $hit
DateTimeImmutable|null $expiresAt

getKey

string getKey()

Returns the immutable key associated with this item.

Return Value

string

get

mixed get()

Returns the value currently held by this item.

Return Value

mixed

isHit

bool isHit()

Reports a hit only when the item originated as one and has not expired.

Return Value

bool

set

CacheItem set(mixed $value)

Replaces the held value and returns this item for fluent mutation.

Parameters

mixed $value

Return Value

CacheItem

expiresAt

CacheItem expiresAt(DateTimeInterface|null $expiration)

Sets an absolute expiration using an immutable copy, or clears it with null.

Parameters

DateTimeInterface|null $expiration

Return Value

CacheItem

expiresAfter

CacheItem expiresAfter(DateInterval|int|null $time)

Sets expiration relative to now, clamps negative seconds to zero, or clears it with null.

Parameters

DateInterval|int|null $time

Return Value

CacheItem

expiresAtDate

DateTimeImmutable|null expiresAtDate()

Exposes the normalized absolute expiration used by framework pool implementations.

Return Value

DateTimeImmutable|null