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 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

A dependency aware cache repository for Laravel

Frequently asked questions about Laravel Dependency Aware Cache
How do I install this package in my Laravel project?
Run `composer require craftcms/laravel-dependency-aware-cache` to install. No additional configuration is needed—the package integrates seamlessly with Laravel’s built-in `Cache` facade. Use `DependencyCache::store()` for extended functionality.
Does this work with all Laravel cache drivers (Redis, database, file, etc.)?
Yes, the package supports all Laravel cache drivers out of the box. It extends Laravel’s native `CacheManager`, so existing driver configurations remain unchanged. Tested drivers include Redis, Memcached, file, and database-backed caching.
What Laravel versions are supported?
The package is designed for Laravel 8.x and 9.x. Check the [GitHub repo](https://github.com/craftcms/laravel-dependency-aware-cache) for the latest compatibility notes. It leverages Laravel’s caching abstractions, so updates align with Laravel’s release cycle.
How do dependencies work? Are they stored in-memory or persisted?
Dependencies are tracked in-memory during runtime and are not persisted across server restarts. They are tied to cache keys and invalidated when their associated triggers (e.g., tags, file changes, or callbacks) occur. For distributed systems, ensure all instances share the same cache driver.
Can I use this for high-traffic APIs or queue workers?
The package is thread-safe for concurrent reads but may introduce slight overhead during invalidation. For queue workers, ensure dependencies are invalidated before processing to avoid stale data. Test under load, as dependency checks add minimal latency (typically <50ms per operation).
What happens if dependency invalidation fails (e.g., Redis connection drops)?
Invalidation failures are silent by default but can be logged by extending the package or wrapping calls in try-catch blocks. The package does not guarantee atomicity—always handle fallback logic in your application (e.g., retry or notify admins).
How do I create custom dependency types (e.g., database-based or API-triggered)?
Extend the base `Dependency` class or use `CallbackDependency` for dynamic logic. Example: `new CallbackDependency(fn() => Model::find($id)->updated_at)`. The package supports `TagDependency`, `FileDependency`, and `ValueDependency` out of the box, with room for customization.
Does this package integrate with Laravel events (e.g., Model::saved)?
Yes, you can manually trigger invalidation via `TagDependency::invalidate('tag')` or listen to Laravel events (e.g., `Model::saved`) to call invalidation logic. The package emits `TagsInvalidated` events, but you’ll need to wire these up yourself for full event-driven workflows.
What’s the performance impact compared to Laravel’s built-in `Cache::tags()`?
Dependency-aware caching adds ~5–50ms overhead per operation due to dependency checks, but it’s more granular than tags. For simple use cases, `Cache::tags()` may suffice. Benchmark your workload—this package shines in complex scenarios (e.g., invalidating caches tied to multiple dynamic conditions).
Are there alternatives to this package for dependency-aware caching in Laravel?
Laravel’s native `Cache::tags()` is the simplest alternative, but it lacks advanced dependency types. For richer features, consider `spatie/laravel-cache-control` (for HTTP caching) or `predis/predis` (Redis-specific). This package is ideal if you need Yii-style dependency tracking with Laravel’s ecosystem.
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.
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
spatie/mailcoach-vapor
spatie/laravel-javascript-views