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.

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.

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 62
__construct(Container $app)

Create a new Cache manager instance.

Parameters

Container $app

at line 73
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 87
Repository driver(UnitEnum|string|null $driver = null)

Get a cache driver instance.

Parameters

UnitEnum|string|null $driver

Return Value

Repository

at line 98
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 118
protected Repository createMemoizedRepository(string $driver)

Create a memoized repository for the given driver.

Parameters

string $driver

Return Value

Repository

at line 139
Repository resolve(string $name)

Resolve the given store.

Parameters

string $name

Return Value

Repository

Exceptions

InvalidArgumentException

at line 157
Repository build(array $config)

Build a cache repository with the given configuration.

Parameters

array $config

Return Value

Repository

Exceptions

InvalidArgumentException

at line 177
protected Repository callCustomCreator(array $config)

Call a custom driver creator.

Parameters

array $config

Return Value

Repository

at line 187
protected Repository createArrayDriver(array $config)

Create an instance of the array cache driver.

Parameters

array $config

Return Value

Repository

at line 198
protected Repository createWorkerArrayDriver(array $config)

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

Parameters

array $config

Return Value

Repository

at line 209
protected Repository createDatabaseDriver(array $config)

Create an instance of the database cache driver.

Parameters

array $config

Return Value

Repository

at line 236
protected Repository createFailoverDriver(array $config)

Create an instance of the failover cache driver.

Parameters

array $config

Return Value

Repository

at line 249
protected Repository createFileDriver(array $config)

Create an instance of the file cache driver.

Parameters

array $config

Return Value

Repository

at line 266
protected Repository createStorageDriver(array $config)

Create an instance of the storage cache driver.

Parameters

array $config

Return Value

Repository

at line 281
protected Repository createNullDriver()

Create an instance of the Null cache driver.

Return Value

Repository

at line 289
protected Repository createRedisDriver(array $config)

Create an instance of the Redis cache driver.

Parameters

array $config

Return Value

Repository

at line 313
protected Repository createSessionDriver(array $config)

Create an instance of the session cache driver.

Parameters

array $config

Return Value

Repository

at line 329
protected Session getSession()

Get the session store implementation.

Return Value

Session

Exceptions

InvalidArgumentException

at line 341
protected Repository createSwooleDriver(array $config)

Create an instance of the Swoole cache driver.

Parameters

array $config

Return Value

Repository

at line 358
protected Repository createStackDriver(array $config)

Create an instance of the Stack cache driver.

Parameters

array $config

Return Value

Repository

at line 377
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 389
protected void setEventDispatcher(Repository $repository)

Set the event dispatcher on the given repository instance.

Parameters

Repository $repository

Return Value

void

at line 408
void refreshEventDispatcher()

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

Boot or tests only. 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 421
protected string getPrefix(array $config)

Get the cache prefix.

Parameters

array $config

Return Value

string

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

Get the cache connection configuration.

Parameters

string $name

Return Value

array|null

at line 444
string getDefaultDriver()

Get the default cache driver name.

Return Value

string

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

Set the default cache driver name.

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

Parameters

UnitEnum|string $name

Return Value

void

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

Unset the given driver instances.

Boot or tests only. 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 496
void purge(UnitEnum|string|null $name = null)

Disconnect the given driver and remove from local cache.

Boot or tests only. 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 518
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.

Boot-only. 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 539
CacheManager setApplication(Container $app)

Set the application instance used by the manager.

Tests only. 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 558
CacheManager allowSerializableClassesUsing(Closure $resolver)

Register classes that cache stores may unserialize.

Boot-only. The resolver contributes to the worker-lifetime cache policy and is evaluated at application boot completion in console processes or after the worker configuration is rebuilt in Swoole workers. An earlier cache read evaluates the current contributions without memoizing them.

Parameters

Closure $resolver

Return Value

CacheManager

Exceptions

LogicException

at line 573
void finalizeSerializableClasses()

internal  
 

Finalize the worker-lifetime serializable class policy.

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

Return Value

void

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

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

Boot or tests only. The callback persists for the worker lifetime and affects every subsequent cache read.

Parameters

callable|null $callback

Return Value

void

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

Dynamically call the default driver instance.

Parameters

string $method
array $parameters

Return Value

mixed