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 all resolved 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 61
__construct(Container $app)

Create a new Cache manager instance.

Parameters

Container $app

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

Get a cache driver instance.

Parameters

UnitEnum|string|null $driver

Return Value

Repository

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

Create a memoized repository for the given driver.

Parameters

string $driver

Return Value

Repository

at line 138
Repository resolve(string $name)

Resolve the given store.

Parameters

string $name

Return Value

Repository

Exceptions

InvalidArgumentException

at line 156
Repository build(array $config)

Build a cache repository with the given configuration.

Parameters

array $config

Return Value

Repository

Exceptions

InvalidArgumentException

at line 176
protected Repository callCustomCreator(array $config)

Call a custom driver creator.

Parameters

array $config

Return Value

Repository

at line 184
protected Repository createArrayDriver(array $config)

Create an instance of the array cache driver.

Parameters

array $config

Return Value

Repository

at line 195
protected Repository createWorkerArrayDriver(array $config)

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

Parameters

array $config

Return Value

Repository

at line 206
protected Repository createDatabaseDriver(array $config)

Create an instance of the database cache driver.

Parameters

array $config

Return Value

Repository

at line 231
protected Repository createFailoverDriver(array $config)

Create an instance of the failover cache driver.

Parameters

array $config

Return Value

Repository

at line 243
protected Repository createFileDriver(array $config)

Create an instance of the file cache driver.

Parameters

array $config

Return Value

Repository

at line 260
protected Repository createStorageDriver(array $config)

Create an instance of the storage cache driver.

Parameters

array $config

Return Value

Repository

at line 273
protected Repository createNullDriver()

Create an instance of the Null cache driver.

Return Value

Repository

at line 281
protected Repository createRedisDriver(array $config)

Create an instance of the Redis cache driver.

Parameters

array $config

Return Value

Repository

at line 305
protected Repository createSessionDriver(array $config)

Create an instance of the session cache driver.

Parameters

array $config

Return Value

Repository

at line 321
protected Session getSession()

Get the session store implementation.

Return Value

Session

Exceptions

InvalidArgumentException

at line 333
protected Repository createSwooleDriver(array $config)

Create an instance of the Swoole cache driver.

Parameters

array $config

Return Value

Repository

at line 350
protected Repository createStackDriver(array $config)

Create an instance of the Stack cache driver.

Parameters

array $config

Return Value

Repository

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

Set the event dispatcher on the given repository instance.

Parameters

Repository $repository

Return Value

void

at line 400
void refreshEventDispatcher()

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

Boot or tests only. Replaces the dispatcher on every cached repository for the worker lifetime; per-request use races across coroutines. Reached by Event::fake() / Event::fakeFor() to point cached repositories at the fake dispatcher and to restore them afterwards.

Return Value

void

at line 408
protected string getPrefix(array $config)

Get the cache prefix.

Parameters

array $config

Return Value

string

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

Get the cache connection configuration.

Parameters

string $name

Return Value

array|null

at line 431
string getDefaultDriver()

Get the default cache driver name.

Return Value

string

at line 441
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 457
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 481
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 498
CacheManager extend(string $driver, Closure $callback)

Register a custom driver creator Closure.

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 519
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 539
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 after every provider has booted: at application boot completion in console processes or after configuration reload in each Swoole worker. An earlier cache read evaluates the current contributions without memoizing them.

Parameters

Closure $resolver

Return Value

CacheManager

Exceptions

LogicException

at line 554
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 565
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 573
mixed __call(string $method, array $parameters)

Dynamically call the default driver instance.

Parameters

string $method
array $parameters

Return Value

mixed