class CacheManager implements Factory mixin Repository mixin LockProvider mixin TaggableStore

Traits

Constants

protected MEMOIZED_CONTEXT_KEY_PREFIX

The context key prefix for memoized cache repositories.

Properties

protected array $stores

The array of resolved cache stores.

protected array $customCreators

The registered custom driver creators.

protected SerializableClassPolicy $serializableClassPolicy

The serializable class policy shared by built-in cache stores.

Methods

Closure|null
bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

__construct(Container $app)

Create a new Cache manager instance.

store(UnitEnum|string|null $name = null)

Get a cache store instance by name, wrapped in a repository.

driver(UnitEnum|string|null $driver = null)

Get a cache driver instance.

memo(UnitEnum|string|null $driver = null)

Get a memoized cache driver instance.

string
memoizedContextKey(string $driver)

Get this manager's coroutine context key for the given memoized driver.

createMemoizedRepository(string $driver)

Create a memoized repository for the given driver.

resolve(string $name)

Resolve the given store.

build(array $config)

Build a cache repository with the given configuration.

callCustomCreator(array $config)

Call a custom driver creator.

createArrayDriver(array $config)

Create an instance of the array cache driver.

createWorkerArrayDriver(array $config)

Create an instance of the worker-lifetime array cache driver.

createDatabaseDriver(array $config)

Create an instance of the database cache driver.

createFailoverDriver(array $config)

Create an instance of the failover cache driver.

createFileDriver(array $config)

Create an instance of the file cache driver.

createStorageDriver(array $config)

Create an instance of the storage cache driver.

createNullDriver()

Create an instance of the Null cache driver.

createRedisDriver(array $config)

Create an instance of the Redis cache driver.

createSessionDriver(array $config)

Create an instance of the session cache driver.

getSession()

Get the session store implementation.

createSwooleDriver(array $config)

Create an instance of the Swoole cache driver.

createStackDriver(array $config)

Create an instance of the Stack cache driver.

void
ensureStoresAreAcyclic(array $config, array $path = [])

Reject circular built-in store definitions before resolving their layers.

repository(Store $store, array $config = [])

Create a new cache repository with the given implementation.

void
setEventDispatcher(Repository $repository)

Set the event dispatcher on the given repository instance.

void
refreshEventDispatcher()

Re-set the event dispatcher on resolved event-emitting cache repositories.

string
getPrefix(array $config)

Get the cache prefix.

array|null
getConfig(string $name)

Get the cache connection configuration.

string
getDefaultDriver()

Get the default cache driver name.

void
setDefaultDriver(UnitEnum|string $name)

Set the default cache driver name.

forgetDriver(array|UnitEnum|string|null $name = null)

Unset the given driver instances.

void
purge(UnitEnum|string|null $name = null)

Disconnect the given driver and remove from local cache.

extend(string $driver, Closure $callback)

Register a custom driver creator Closure.

setApplication(Container $app)

Set the application instance used by the manager.

allowSerializableClassesUsing(Closure $resolver)

Register classes that cache stores may unserialize.

void
finalizeSerializableClasses()

Finalize the worker-lifetime serializable class policy.

void
handleUnserializableClassUsing(callable|null $callback)

Register a callback to be invoked when an unserializable class is encountered.

mixed
__call(string $method, array $parameters)

Dynamically call the default driver instance.

Details

protected Closure|null bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

Parameters

Closure $callback

Return Value

Closure|null

Exceptions

ReflectionException

at line 79
__construct(Container $app)

Create a new Cache manager instance.

Parameters

Container $app

at line 90
Repository store(UnitEnum|string|null $name = null)

Get a cache store instance by name, wrapped in a repository.

Parameters

UnitEnum|string|null $name

Return Value

Repository

at line 104
Repository driver(UnitEnum|string|null $driver = null)

Get a cache driver instance.

Parameters

UnitEnum|string|null $driver

Return Value

Repository

at line 115
Repository memo(UnitEnum|string|null $driver = null)

Get a memoized cache driver instance.

The memoized repository is isolated to the current coroutine and resets when the coroutine ends.

Parameters

UnitEnum|string|null $driver

Return Value

Repository

at line 135
protected string memoizedContextKey(string $driver)

Get this manager's coroutine context key for the given memoized driver.

Parameters

string $driver

Return Value

string

at line 143
protected Repository createMemoizedRepository(string $driver)

Create a memoized repository for the given driver.

Parameters

string $driver

Return Value

Repository

at line 164
Repository resolve(string $name)

Resolve the given store.

Parameters

string $name

Return Value

Repository

Exceptions

InvalidArgumentException

at line 189
Repository build(array $config)

Build a cache repository with the given configuration.

Parameters

array $config

Return Value

Repository

Exceptions

InvalidArgumentException

at line 209
protected Repository callCustomCreator(array $config)

Call a custom driver creator.

Parameters

array $config

Return Value

Repository

at line 219
protected Repository createArrayDriver(array $config)

Create an instance of the array cache driver.

Parameters

array $config

Return Value

Repository

at line 230
protected Repository createWorkerArrayDriver(array $config)

Create an instance of the worker-lifetime array cache driver.

Parameters

array $config

Return Value

Repository

at line 241
protected Repository createDatabaseDriver(array $config)

Create an instance of the database cache driver.

Parameters

array $config

Return Value

Repository

at line 268
protected Repository createFailoverDriver(array $config)

Create an instance of the failover cache driver.

Parameters

array $config

Return Value

Repository

at line 283
protected Repository createFileDriver(array $config)

Create an instance of the file cache driver.

Parameters

array $config

Return Value

Repository

at line 300
protected Repository createStorageDriver(array $config)

Create an instance of the storage cache driver.

Parameters

array $config

Return Value

Repository

at line 315
protected Repository createNullDriver()

Create an instance of the Null cache driver.

Return Value

Repository

at line 323
protected Repository createRedisDriver(array $config)

Create an instance of the Redis cache driver.

Parameters

array $config

Return Value

Repository

at line 347
protected Repository createSessionDriver(array $config)

Create an instance of the session cache driver.

Parameters

array $config

Return Value

Repository

at line 363
protected Session getSession()

Get the session store implementation.

Return Value

Session

Exceptions

InvalidArgumentException

at line 375
protected Repository createSwooleDriver(array $config)

Create an instance of the Swoole cache driver.

Parameters

array $config

Return Value

Repository

at line 392
protected Repository createStackDriver(array $config)

Create an instance of the Stack cache driver.

Parameters

array $config

Return Value

Repository

at line 415
protected void ensureStoresAreAcyclic(array $config, array $path = [])

Reject circular built-in store definitions before resolving their layers.

Parameters

array $config
array $path

Return Value

void

at line 451
Repository repository(Store $store, array $config = [])

Create a new cache repository with the given implementation.

Parameters

Store $store
array $config

Return Value

Repository

at line 463
protected void setEventDispatcher(Repository $repository)

Set the event dispatcher on the given repository instance.

Parameters

Repository $repository

Return Value

void

at line 482
void refreshEventDispatcher()

Re-set the event dispatcher on resolved event-emitting cache repositories.

Replaces the dispatcher on cached concrete repositories that already emit events, preserving disabled stores and custom repository implementations. Per-request use races across coroutines. Reached by Event::fake() / Event::fakeFor() to install and restore fake dispatchers.

Return Value

void

at line 496
protected string getPrefix(array $config)

Get the cache prefix.

Parameters

array $config

Return Value

string

at line 507
protected array|null getConfig(string $name)

Get the cache connection configuration.

Parameters

string $name

Return Value

array|null

at line 519
string getDefaultDriver()

Get the default cache driver name.

Return Value

string

at line 529
void setDefaultDriver(UnitEnum|string $name)

Set the default cache driver name.

Mutates process-global config; per-request use races across coroutines.

Parameters

UnitEnum|string $name

Return Value

void

at line 548
CacheManager forgetDriver(array|UnitEnum|string|null $name = null)

Unset the given driver instances.

Mutates the singleton's store cache; concurrent coroutines may already hold a reference to the store and next resolution will rebuild with fresh connections.

Parameters

array|UnitEnum|string|null $name

Return Value

CacheManager

at line 575
void purge(UnitEnum|string|null $name = null)

Disconnect the given driver and remove from local cache.

Mutates the singleton's store cache; concurrent coroutines may already hold a reference to the store and next resolution will rebuild with fresh connections.

Parameters

UnitEnum|string|null $name

Return Value

void

at line 598
CacheManager extend(string $driver, Closure $callback)

Register a custom driver creator Closure.

Anonymous closures run in this manager's class scope; non-static closures also receive the manager as $this.

The callback persists in the singleton's customCreators array for the worker lifetime and applies to every subsequent store resolution.

Parameters

string $driver
Closure $callback

Return Value

CacheManager

at line 622
CacheManager setApplication(Container $app)

Set the application instance used by the manager.

Swaps the singleton's container reference; per-request use races across coroutines and breaks every concurrent request resolving stores through this manager.

Parameters

Container $app

Return Value

CacheManager

at line 644
CacheManager allowSerializableClassesUsing(Closure $resolver)

Register classes that cache stores may unserialize.

The resolver contributes to the worker-lifetime cache policy and is evaluated when the application finishes booting in console processes, after configuration reload in Swoole workers, or before a custom server process starts handling work. An earlier cache read evaluates the current contributions without memoizing them.

Parameters

Closure $resolver

Return Value

CacheManager

Exceptions

LogicException

at line 660
void finalizeSerializableClasses()

internal  
 

Finalize the worker-lifetime serializable class policy.

The policy is frozen for the worker lifetime; later contributions throw and every subsequent unserialize uses the frozen list.

Return Value

void

at line 672
void handleUnserializableClassUsing(callable|null $callback)

Register a callback to be invoked when an unserializable class is encountered.

The callback persists for the worker lifetime and affects every subsequent cache read.

Parameters

callable|null $callback

Return Value

void

at line 681
mixed __call(string $method, array $parameters)

Dynamically call the default driver instance.

Parameters

string $method
array $parameters

Return Value

mixed