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

Laravel Model Cache Laravel Package

ymigval/laravel-model-cache

View on GitHub
Deep Wiki
Context7

Laravel Model Cache is an efficient and easy-to-implement caching solution for Laravel Eloquent models. It provides automatic cache invalidation when models are created, updated, deleted, or restored.

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