Cache
class Cache
Caching with namespace isolation, dependency tracking, and stampede prevention.
Constants
| Priority |
dependency |
| Expire |
dependency |
| Sliding |
dependency |
| Tags |
dependency |
| Files |
dependency |
| Items |
dependency |
| Constants |
dependency |
| Callbacks |
dependency |
| Namespaces |
dependency |
| All |
dependency |
| deprecated PRIORITY |
|
| deprecated EXPIRATION |
|
| deprecated EXPIRE |
|
| deprecated SLIDING |
|
| deprecated TAGS |
|
| deprecated FILES |
|
| deprecated ITEMS |
|
| deprecated CONSTS |
|
| deprecated CALLBACKS |
|
| deprecated NAMESPACES |
|
| deprecated ALL |
|
| internal NamespaceSeparator |
|
| internal NAMESPACE_SEPARATOR |
|
Methods
No description
No description
Returns a cached item, or generates and stores it using the given callback.
No description
Stores item in the cache and returns it.
Stores multiple items in the cache at once.
No description
Removes items from the cache by conditions:
- Cache::Priority => (int) removes items with equal or lower priority
- Cache::Tags => (array) removes items with matching tags
- Cache::All => true clears the entire cache
Calls a function and caches its result. Subsequent calls with the same arguments return the cached value.
Returns a cached wrapper around a function. Each unique set of arguments is cached separately.
Starts output buffering for caching. Returns null and echoes cached content if already cached, or returns an OutputHelper to capture and save new output.
Generates a namespaced storage key from a user-provided key.
Validates all callback dependencies. Returns false if any callback returns false.
Details
at line 74
__construct(Storage $storage, string|null $namespace = null)
No description
at line 81
final Storage
getStorage()
No description
at line 87
final string
getNamespace()
No description
at line 96
Cache
derive(string $namespace)
Returns a new cache object scoped to a sub-namespace.
at line 107
mixed
load(mixed $key, callable|null $generator = null, array|null $dependencies = null)
Returns a cached item, or generates and stores it using the given callback.
at line 134
array
bulkLoad(array $keys, callable|null $generator = null)
No description
at line 191
mixed
save(mixed $key, mixed $data, array|null $dependencies = null)
Stores item in the cache and returns it.
Dependencies:
- Cache::Priority => (int) priority
- Cache::Expire => (string|int) expiration time, infinite if null
- Cache::Sliding => (bool) use sliding expiration?
- Cache::Tags => (array) tags
- Cache::Files => (array|string) file paths
- Cache::Items => (array|string) dependent cache keys
- Cache::Constants => (array|string) PHP constant names
at line 226
void
bulkSave(array $items, array|null $dependencies = null)
Stores multiple items in the cache at once.
at line 314
void
remove(mixed $key)
No description
at line 327
void
clean(array|null $conditions = null)
Removes items from the cache by conditions:
- Cache::Priority => (int) removes items with equal or lower priority
- Cache::Tags => (array) removes items with matching tags
- Cache::All => true clears the entire cache
at line 341
mixed
call(callable $function)
Calls a function and caches its result. Subsequent calls with the same arguments return the cached value.
at line 357
Closure
wrap(callable $function, array|null $dependencies = null)
Returns a cached wrapper around a function. Each unique set of arguments is cached separately.
at line 377
OutputHelper|null
capture(mixed $key)
Starts output buffering for caching. Returns null and echoes cached content if already cached, or returns an OutputHelper to capture and save new output.
at line 392
OutputHelper|null
start(mixed $key)
deprecated
deprecated
No description
at line 401
protected string
generateKey(mixed $key)
Generates a namespaced storage key from a user-provided key.
at line 414
static bool
checkCallbacks(array $callbacks)
Validates all callback dependencies. Returns false if any callback returns false.