Download the PHP package philiprehberger/laravel-cache-toolkit without Composer
On this page you can find all versions of the php package philiprehberger/laravel-cache-toolkit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download philiprehberger/laravel-cache-toolkit
More information about philiprehberger/laravel-cache-toolkit
Files in philiprehberger/laravel-cache-toolkit
Package laravel-cache-toolkit
Short Description Standardized cache key builder and tag-aware cache operations for Laravel with graceful fallback for non-tagging drivers
License MIT
Homepage https://github.com/philiprehberger/laravel-cache-toolkit
Informations about the package laravel-cache-toolkit
Laravel Cache Toolkit
Standardized cache key builder and tag-aware cache operations for Laravel with graceful fallback for non-tagging drivers.
Requirements
- PHP 8.2+
- Laravel 11 or 12
Installation
The service provider is auto-discovered by Laravel. Optionally publish the config file:
This places config/cache-toolkit.php into your application.
Usage
CacheKeyBuilder
CacheKeyBuilder is a static utility class for building consistent, predictable cache keys.
CacheTagManager
CacheTagManager wraps Laravel's Cache facade with tag-aware operations. When the driver does not support tags (file, array, database) all operations fall back transparently to plain cache calls.
Configuration
API
CacheKeyBuilder
| Method | Description | Returns |
|---|---|---|
CacheKeyBuilder::make(string ...$parts) |
Build a key from arbitrary parts (empty parts filtered) | string |
CacheKeyBuilder::forModel(Model $model, string ...$suffix) |
Build a key from a model instance | string |
CacheKeyBuilder::forModelType(string $class, int\|string $id, string ...$suffix) |
Build a key from a class name and ID | string |
CacheKeyBuilder::forList(string $type, array $filters = []) |
Build a list key with optional filter hash | string |
CacheKeyBuilder::forPaginated(string $type, int $page, int $perPage, array $filters = []) |
Build a paginated list key | string |
CacheKeyBuilder::forAnalytics(string $type, ?string $from = null, ?string $to = null) |
Build an analytics key | string |
CacheKeyBuilder::forUser(int $userId, string $type) |
Build a user-scoped key | string |
CacheKeyBuilder::forDateRange(string $type, string $from, string $to) |
Build a date-range key | string |
CacheKeyBuilder::ttl(string $key) |
Get TTL in seconds from config | int |
CacheKeyBuilder::ttlCarbon(string $key) |
Get TTL as Carbon instance | DateTimeInterface |
CacheKeyBuilder::tags(string $type) |
Get tag array from config | string[] |
CacheKeyBuilder::supportsTags() |
Check if current driver supports tags | bool |
CacheTagManager
| Method | Description | Returns |
|---|---|---|
->remember(string $ttlKey, callable $callback, array $tags, string ...$keyParts) |
Get or store a value | mixed |
->put(string $key, mixed $value, int $ttl, array $tags = []) |
Store a value | void |
->get(string $key, array $tags = []) |
Retrieve a value | mixed |
->has(string $key, array $tags = []) |
Check existence | bool |
->forget(string $key, array $tags = []) |
Remove a value | void |
->flush(array $tags) |
Flush all entries for given tags | bool |
->flushType(string $type) |
Flush entries for a config-defined type | bool |
->flushTypes(string[] $types) |
Flush multiple config-defined types | bool[] |
Tag Driver Support
| Driver | Tags Supported | Behaviour |
|---|---|---|
redis |
Yes | Tags used for grouping and invalidation |
memcached |
Yes | Tags used for grouping and invalidation |
file |
No | Falls back to plain cache; flush returns false |
array |
No | Falls back to plain cache; flush returns false |
database |
No | Falls back to plain cache; flush returns false |
Development
Support
If you find this project useful:
License
MIT
All versions of laravel-cache-toolkit with dependencies
illuminate/cache Version ^11.0|^12.0
illuminate/config Version ^11.0|^12.0
illuminate/database Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0