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 do I install ymigval/laravel-model-cache in a Laravel app?
Install it with composer require ymigval/laravel-model-cache. Optionally publish the config file with php artisan vendor:publish --provider="YMigVal\LaravelModelCache\ModelCacheServiceProvider" --tag="config". Laravel package discovery registers the service provider automatically, then you add the HasCachedQueries trait to the models you want cached.
Which Laravel and PHP versions does laravel-model-cache support?
The README lists PHP 7.4 through 8.4 and Laravel 8.x through 13.x. The Laravel 13 claim is a forward-compatibility statement, so verify it against your exact framework version and run your test suite. Eloquent Builder signatures change across majors, and a broken builder override fails at query time rather than install time.
How do I enable caching for an Eloquent model?
Add the HasCachedQueries trait to the model. The package overrides newEloquentBuilder() to return a cache-aware builder, so existing get() and first() calls become cached without changing call-site syntax. You can configure the default TTL, cache key prefix, cache store, and a global enabled toggle in config/model-cache.php.
How does cache invalidation work in laravel-model-cache?
Invalidation is event-based and responds to model created, updated, deleted, and restored events. A ModelRelationships trait covers pivot operations. Writes that bypass model events, such as Model::where(...)->update(), upsert(), query-builder inserts, seeders, imports, raw SQL, or another service writing to the same database, can leave stale entries. Plan a deploy-time cache flush when model classes or serialized model shapes change.
Does laravel-model-cache work with Redis, Memcached, file, or array cache stores?
Targeted invalidation depends on a tag-capable store such as Redis, Memcached, or the database driver. File and array stores technically work but fall back to clearing the entire cache on invalidation, which is acceptable in development but not ideal in production. Provisioning a dedicated Redis store and key prefix is effectively a prerequisite for production use.
Will laravel-model-cache handle complex queries, pagination, whereIn, or user-scoped filters?
Cache keys are derived from SQL, bindings, and model class, so simple where clauses get correct keys for free. Dynamic whereIn arrays, pagination offsets, user-scoped filters, and sort permutations multiply key cardinality, and the package does not document a key-cardinality bound. There is also no documented stampede or lock protection and no hit/miss instrumentation, so size and monitor the cache yourself. Avoid transparent caching for highly dynamic queries.
What happens if my model already has a custom Eloquent builder?
The package replaces the model builder with CacheableBuilder, so any model that already uses a custom builder can conflict. The app builder would need to extend CacheableBuilder, which couples your builder hierarchy to a third-party class. Packages that decorate or extend the Eloquent builder, such as search-style integrations, should be tested carefully before adopting this package.
Does laravel-model-cache work with database transactions or multi-tenant connections?
The README does not document whether results queried inside an open transaction are cached, or whether the database connection name is part of the cache key. That matters for multi-connection and multi-tenant applications where the same query string can return different rows per tenant. Treat connection and tenant scoping as a spike item and verify the generated keys before relying on the package in those setups.
Can I disable caching globally or bypass the cache for a specific query?
The published configuration includes a global enabled toggle, so you can disable model caching per environment. The package also advertises explicit control methods for cache behavior, and the maintainer discussion references withoutCache() for per-query bypass. Confirm the exact bypass behavior in the source for your installed version and test it in your own query paths.
Is ymigval/laravel-model-cache production-ready and actively maintained?
It is MIT licensed with a single maintainer and modest adoption, around 78 stars and no known dependents, so there is limited third-party validation of edge cases. It fits read-heavy Laravel 8 through 12 applications on Redis with low write rates and tolerant freshness windows, such as catalogs, CMS content, taxonomy, or feature/config lookups. It is a poor fit for strict-consistency domains, heavy bulk-write paths, or applications that cannot tolerate silent staleness. Pin the version, add integration tests, monitor hit rates and key growth, and keep a cache flush in your deploy process.
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.
ably/pubsub-server
mstfkhazaal/defender
mfonte/base62x
karnoweb/metapilot
tobya/bcsapiwrapper
swalker2/cpanel
vish4395/laravel-translation-manager
morningtrain/economic
teksite/systeminfo-laravel
atomcms/voting
run6/weather
siokas/laravelembeddirectives
adamlien/pkuuids
gilsonsouza/lara-doc-generator
manelgavalda/enrollment_mobile
unabomber/timezone
delatbabel/contacts
astritzeqiri/g-recaptcha
kevinongko/laravel-genode
developeruz/laravel-analytics