CacheManager
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
Get a cache store instance by name, wrapped in a repository.
Get a cache driver instance.
Get a memoized cache driver instance.
Get this manager's coroutine context key for the given memoized driver.
Create a memoized repository for the given driver.
Resolve the given store.
Build a cache repository with the given configuration.
Call a custom driver creator.
Create an instance of the array cache driver.
Create an instance of the worker-lifetime array cache driver.
Create an instance of the database cache driver.
Create an instance of the failover cache driver.
Create an instance of the file cache driver.
Create an instance of the storage cache driver.
Create an instance of the Null cache driver.
Create an instance of the Redis cache driver.
Create an instance of the session cache driver.
Get the session store implementation.
Create an instance of the Swoole cache driver.
Create an instance of the Stack cache driver.
Reject circular built-in store definitions before resolving their layers.
Create a new cache repository with the given implementation.
Set the event dispatcher on the given repository instance.
Re-set the event dispatcher on resolved event-emitting cache repositories.
Get the cache prefix.
Get the cache connection configuration.
Get the default cache driver name.
Set the default cache driver name.
Unset the given driver instances.
Disconnect the given driver and remove from local cache.
Register classes that cache stores may unserialize.
Finalize the worker-lifetime serializable class policy.
Register a callback to be invoked when an unserializable class is encountered.
Dynamically call the default driver instance.
Details
in
RebindsCallbacksToSelf at line 18
protected Closure|null
bindCallbackToSelf(Closure $callback)
Bind the provided callback to the class instance.
at line 79
__construct(Container $app)
Create a new Cache manager instance.
at line 90
Repository
store(UnitEnum|string|null $name = null)
Get a cache store instance by name, wrapped in a repository.
at line 104
Repository
driver(UnitEnum|string|null $driver = null)
Get a cache driver instance.
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.
at line 135
protected string
memoizedContextKey(string $driver)
Get this manager's coroutine context key for the given memoized driver.
at line 143
protected Repository
createMemoizedRepository(string $driver)
Create a memoized repository for the given driver.
at line 164
Repository
resolve(string $name)
Resolve the given store.
at line 189
Repository
build(array $config)
Build a cache repository with the given configuration.
at line 209
protected Repository
callCustomCreator(array $config)
Call a custom driver creator.
at line 219
protected Repository
createArrayDriver(array $config)
Create an instance of the array cache driver.
at line 230
protected Repository
createWorkerArrayDriver(array $config)
Create an instance of the worker-lifetime array cache driver.
at line 241
protected Repository
createDatabaseDriver(array $config)
Create an instance of the database cache driver.
at line 268
protected Repository
createFailoverDriver(array $config)
Create an instance of the failover cache driver.
at line 283
protected Repository
createFileDriver(array $config)
Create an instance of the file cache driver.
at line 300
protected Repository
createStorageDriver(array $config)
Create an instance of the storage cache driver.
at line 315
protected Repository
createNullDriver()
Create an instance of the Null cache driver.
at line 323
protected Repository
createRedisDriver(array $config)
Create an instance of the Redis cache driver.
at line 347
protected Repository
createSessionDriver(array $config)
Create an instance of the session cache driver.
at line 363
protected Session
getSession()
Get the session store implementation.
at line 375
protected Repository
createSwooleDriver(array $config)
Create an instance of the Swoole cache driver.
at line 392
protected Repository
createStackDriver(array $config)
Create an instance of the Stack cache driver.
at line 415
protected void
ensureStoresAreAcyclic(array $config, array $path = [])
Reject circular built-in store definitions before resolving their layers.
at line 451
Repository
repository(Store $store, array $config = [])
Create a new cache repository with the given implementation.
at line 463
protected void
setEventDispatcher(Repository $repository)
Set the event dispatcher on the given repository instance.
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.
at line 496
protected string
getPrefix(array $config)
Get the cache prefix.
at line 507
protected array|null
getConfig(string $name)
Get the cache connection configuration.
at line 519
string
getDefaultDriver()
Get the default cache driver name.
at line 529
void
setDefaultDriver(UnitEnum|string $name)
Set the default cache driver name.
Mutates process-global config; per-request use races across coroutines.
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.
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.
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.
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.
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.
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.
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.
at line 681
mixed
__call(string $method, array $parameters)
Dynamically call the default driver instance.