An implementation of Yii's cache with dependencies for Laravel
You can install the package via composer:
composer require craftcms/laravel-dependency-aware-cacheThe 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();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'); // nullOther 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
AnyDependencyorAllDependencies.
You can implement your own dependency by extending Dependency.
composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
Please see License File for more information.