final class CacheManager (View source)

Provides cache-aside convenience operations over one PSR-6 cache pool.

The manager keeps no cache state of its own and delegates persistence and invalidation to the pool.

Methods

__construct(CacheItemPoolInterface $pool)

Binds convenience operations to the pool that owns cached state.

CacheItemPoolInterface
pool()

Exposes the underlying pool for operations outside the manager's convenience API.

CacheItemPoolInterface
mixed
remember(string $key, int|null $ttlSeconds, callable $callback)

Returns a cached value or computes and stores it with the requested lifetime.

mixed
mixed
rememberForever(string $key, callable $callback)

Returns a cached value or computes and stores it without expiration.

mixed
mixed
get(string $key, mixed $default = null)

Returns the cached value for a hit and the supplied default for a miss.

mixed
bool
put(string $key, mixed $value, int|null $ttlSeconds = null)

Stores a value and clears expiration with null or clamps a non-positive lifetime to immediate expiry.

bool
bool
has(string $key)

Reports whether the underlying pool contains a live item for the key.

bool
bool
forget(string $key)

Removes one key through the underlying pool.

bool
bool
clear()

Removes all entries owned by the underlying pool.

bool

Details

__construct

__construct(CacheItemPoolInterface $pool)

Binds convenience operations to the pool that owns cached state.

Parameters

CacheItemPoolInterface $pool

pool

CacheItemPoolInterface pool()

Exposes the underlying pool for operations outside the manager's convenience API.

Return Value

CacheItemPoolInterface

remember

mixed remember(string $key, int|null $ttlSeconds, callable $callback)

Returns a cached value or computes and stores it with the requested lifetime.

Parameters

string $key
int|null $ttlSeconds
callable $callback

Return Value

mixed

Exceptions

InvalidArgumentException

rememberForever

mixed rememberForever(string $key, callable $callback)

Returns a cached value or computes and stores it without expiration.

Parameters

string $key
callable $callback

Return Value

mixed

Exceptions

InvalidArgumentException

get

mixed get(string $key, mixed $default = null)

Returns the cached value for a hit and the supplied default for a miss.

Parameters

string $key
mixed $default

Return Value

mixed

Exceptions

InvalidArgumentException

put

bool put(string $key, mixed $value, int|null $ttlSeconds = null)

Stores a value and clears expiration with null or clamps a non-positive lifetime to immediate expiry.

Parameters

string $key
mixed $value
int|null $ttlSeconds

Return Value

bool

Exceptions

InvalidArgumentException

has

bool has(string $key)

Reports whether the underlying pool contains a live item for the key.

Parameters

string $key

Return Value

bool

Exceptions

InvalidArgumentException

forget

bool forget(string $key)

Removes one key through the underlying pool.

Parameters

string $key

Return Value

bool

Exceptions

InvalidArgumentException

clear

bool clear()

Removes all entries owned by the underlying pool.

Return Value

bool