Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Dependency Aware Cache Laravel Package

craftcms/laravel-dependency-aware-cache

Laravel cache extension that tracks dependencies and automatically invalidates cached items when related keys change. Useful for keeping derived or aggregated data fresh without manual cache flushing. Designed for straightforward integration with Laravel’s cache system.

View on GitHub
Deep Wiki
Context7

Dependency-aware cache for Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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 or AllDependencies.

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky