Weave 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 Model Cache

Laravel Model Cache Laravel Package

ymigval/laravel-model-cache

Transparently caches Eloquent query results with zero syntax changes, auto-invalidating on create, update, delete, and restore. Configurable TTL, stores, and tags for read-heavy Laravel apps.

View on GitHub
Deep Wiki
Context7

Laravel package for caching Eloquent model queries

Frequently asked questions about Laravel Model Cache
How does this package differ from manually wrapping Eloquent queries with Cache::remember?
This package replaces Laravel’s query builder entirely with a cache-aware version, so *all* queries (get(), first(), etc.) are cached automatically without manual wrappers. It also handles invalidation via model events, reducing boilerplate significantly.
Will this break existing query logic (e.g., scopes, relationships, or custom accessors)?
No—it’s a drop-in replacement. All Eloquent features (scopes, relationships, accessors) work unchanged. The package only intercepts query execution to add caching, leaving your query logic intact.
What’s the best cache driver for production? Does it support Redis tags?
Redis is recommended for production due to its atomic operations and tag support. The package leverages Laravel’s built-in cache tagging, so invalidation works efficiently even with bulk operations.
How does cache invalidation work for bulk updates (e.g., Model::update([...]))?
Bulk operations bypass individual model events, so you’ll need to manually invalidate tags for affected models. The package provides helper methods like `ModelCache::invalidateTag()` for this purpose.
Can I mix explicit and transparent caching in the same app?
Yes. Use `getFromCache()` or `firstFromCache()` for explicit control, while all other queries (e.g., `Model::all()`) remain transparently cached. This lets you fine-tune caching per use case.
What Laravel versions and PHP versions are officially supported?
The package supports Laravel 8–12 and PHP 7.4–8.3. It’s tested against the latest LTS releases, ensuring compatibility with modern Laravel stacks and dependencies.
How do I handle dynamic queries (e.g., whereIn with variable arrays) to avoid cache key collisions?
The package serializes query parameters into cache keys, but for highly dynamic queries, consider using explicit caching with custom keys or shorter TTLs to mitigate collisions.
What happens if the cache driver fails (e.g., Redis goes down)?
The package falls back to the default cache driver (configurable in `config/model-cache.php`). For graceful degradation, implement a circuit breaker to disable caching temporarily during outages.
How can I monitor cache effectiveness (hit rate, invalidation frequency)?
Use Laravel’s cache driver metrics (e.g., Redis INFO command) or log cache misses via the `cache_miss` event. The package doesn’t include built-in monitoring, but you can extend it with custom listeners.
Are there alternatives for caching Eloquent models in Laravel? What makes this package stand out?
Alternatives like `spatie/laravel-query-builder` or manual `Cache::remember` require manual setup. This package offers transparent caching with zero query changes, automatic invalidation, and deep Eloquent integration—ideal for read-heavy apps.
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.
encore2/laravel-admin2
cboxdk/laravel-console-kit
shapecode/doctrine-dbal-datetimeutc
gilads-otiannoh254/inertia-protocol
dakiquang/laravel-oauth-refresh-lock
woda/laravel-worktrees
dalefranks/ramasite
faghy/laracashbook
roundly-consulting/google-places-for-laravel
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
adachsoft/cli-process-tester
adachsoft/changelog-linter
adachsoft/collection
adachsoft/php-code-style
adachsoft/api-version-bundle
cgv/localized-resource