codewithdennis/laravel-model-cache
Cache Eloquent model queries in Laravel with a single trait. Cached results are automatically invalidated when models are created, updated, or deleted, cutting database load and speeding up repeated reads with minimal setup.
Consider it when all of the following hold:
file/database/array drivers weaken or break tag-based invalidation.DB::table() writer, third-party sync job, or raw mass update is a known gap you've mapped and accepted.^1.0.0-beta.1 exactly and absorb breaking changes before 1.0. It's a single-maintainer, 7-star, pre-1.0 dependency with effectively zero public dependents — no ecosystem validation and no community support safety net. Budget an internal owner, or the willingness to vendor the trait if maintenance lapses.Look elsewhere when:
refresh()/fresh() may return stale data, transaction-commit ordering is unverified, and mass updates bypass invalidation. Use a purpose-built read model instead.Cache::remember gives you more explicit control and no new dependency.local/testing (MODEL_CACHE_ENABLED=false) so the problem stays visible.Default PM stance: approve a timeboxed spike (one model, one branch, measured), not adoption. Adopting a beta package into your data path is a product risk decision, and the score and star count say this is a bet on a small code surface you can read and fork — not on a vendor.
To executives (30 seconds): We have a cheap, reversible experiment that may cut database load and page latency on our read-heavy pages, and could defer an infrastructure purchase by a cycle or two. It costs days, not weeks, and we can switch it off with a config flag. I'm not asking to adopt it broadly: it's a pre-1.0 package from a single developer with no support, so the recommendation is a measured pilot on one low-risk surface with a clear kill criterion. If the numbers don't show up, we walk away having lost a spike and gained real performance data we'd have needed anyway.
To engineering leads: The insertion point is right — the Eloquent layer, below controllers — so existing query code benefits without restructuring. Installation is trivial; the actual work is deciding which models are safe and proving invalidation holds. The real risks are ranked and concrete: silent staleness on writes that bypass Eloquent, invalidation firing before transaction commit, cache keys that don't scope by tenant, and undocumented behavior when Redis is unavailable. My ask is a one-model pilot behind a flag for a full write cycle, with tests asserting invalidation rather than trusting the docs — they're thin at beta. Also: this only pays off on Redis/Memcached; on the file driver, don't bother.
To the team on the ground: Pin the exact beta version, wrap the cached queries behind your own scopes or repository methods so a rename at 1.0 touches one file, keep the package disabled locally so caching doesn't mask N+1s, and write the runbook before launch — how to flush selectively and how to disable during an incident. This is a small enough codebase that forking is realistic if the maintainer disappears, which is exactly why the risk is manageable for a pilot and unacceptable for a silent, org-wide rollout.
How can I help you explore Laravel packages today?