craftcms / laravel-dependency-aware-cache
A dependency aware cache repository for Laravel
Requires
- php: ^8.2
- illuminate/cache: ^10.0||^11.0||^12.0
- illuminate/contracts: ^10.0||^11.0||^12.0
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
README
An implementation of Yii's cache with dependencies for Laravel
Installation
You can install the package via composer:
composer require craftcms/laravel-dependency-aware-cache
Usage
The dependency aware repository is hooked up automatically and will be returned when using the Cache
Facade.
This package also provides a \CraftCms\DependencyAwareCache\Facades\DependencyCache
Facade which extends the default Cache
Facade but provides updated docblocks.
use Illuminate\Support\Facades\Cache; use CraftCms\DependencyAwareCache\DependencyAwareRepository; use CraftCms\DependencyAwareCache\Facades\DependencyCache; /** @var DependencyAwareRepository $cache */ $cache = Cache::store(); /** @var DependencyAwareRepository $cache */ $cache = DependencyCache::store();
Invalidation
When using the cache, you can specify a dependency that may trigger cache invalidation. Below is an example using the tag dependency:
use CraftCms\DependencyAwareCache\Dependency\TagDependency; use Illuminate\Support\Facades\Cache; Cache::put('item_42_price', 10, null, new TagDependency('item_42')); Cache::put('item_42_total', 100, null, new TagDependency('item_42')); Cache::get('item_42_price'); // 10 Cache::get('item_42_total'); // 100 TagDependency::invalidate('item_42'); Cache::get('item_42_price'); // null Cache::get('item_42_total'); // null
Other dependencies:
-
CallbackDependency
- invalidates when the result of a callback changes. -
FileDependency
- invalidates the cache based on file modification time. -
ValueDependency
- invalidates the cache when specified value changes. -
You may combine multiple dependencies using
AnyDependency
orAllDependencies
.
You can implement your own dependency by extending Dependency
.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
Please see License File for more information.