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 |
| PRIORITY |
|
| EXPIRATION |
|
| EXPIRE |
|
| SLIDING |
|
| TAGS |
|
| FILES |
|
| ITEMS |
|
| CONSTS |
|
| CALLBACKS |
|
| NAMESPACES |
|
| ALL |
|
| internal NamespaceSeparator |
|
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.
No description
Generates a namespaced storage key from a user-provided key.
Validates all callback dependencies. Returns false if any callback returns false.
Details
at line 72
__construct(Storage $storage, string|null $namespace = null)
No description
at line 79
final Storage
getStorage()
No description
at line 85
final string
getNamespace()
No description
at line 94
Cache
derive(string $namespace)
Returns a new cache object scoped to a sub-namespace.
at line 105
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 132
array
bulkLoad(array $keys, callable|null $generator = null)
No description
at line 189
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 224
void
bulkSave(array $items, array|null $dependencies = null)
Stores multiple items in the cache at once.
at line 312
void
remove(mixed $key)
No description
at line 325
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 339
mixed
call(callable $function)
Calls a function and caches its result. Subsequent calls with the same arguments return the cached value.
at line 355
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 375
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 387
OutputHelper|null
start(mixed $key)
No description
at line 398
protected string
generateKey(mixed $key)
Generates a namespaced storage key from a user-provided key.
at line 411
static bool
checkCallbacks(array $callbacks)
Validates all callback dependencies. Returns false if any callback returns false.