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 Modelcache

Laravel Modelcache Laravel Package

foxws/laravel-modelcache

Cache Eloquent model queries and results with a simple, fluent API for Laravel. Reduce database load by storing frequently accessed model data in your cache store, with automatic invalidation on updates. Lightweight, easy to configure, and works with any Laravel cache driver.

View on GitHub
Deep Wiki
Context7

Cache helpers for Laravel Eloquent models

Frequently asked questions about Laravel Modelcache
How do I install foxws/laravel-modelcache in a Laravel app?
Install it with composer require foxws/laravel-modelcache. Optionally publish the config file, then add the InteractsWithModelCache trait to each model you want to cache. There are no migrations, no manual service provider registration, and no external dependencies. You can control behavior with the MODEL_CACHE_ENABLED, MODEL_CACHE_STORE, and MODEL_CACHE_LIFETIME environment variables.
Does laravel-modelcache automatically invalidate the cache when a model is updated?
The package description advertises automatic invalidation on create, update, and delete, but the reviewed behavior says otherwise. There are no invalidation hooks, so you are responsible for clearing or versioning keys when the underlying data changes. Read the source and settle this question before you build any feature that depends on invalidation. The safest pattern is to version your cache key names rather than rely on implicit busting.
Which Laravel and PHP versions does foxws/laravel-modelcache support?
The package is a thin convention layer over Laravel's cache contracts, so it works wherever those contracts are available. Check the composer.json constraints on the repository for the exact PHP and illuminate/support ranges before adopting it. Release metadata on the project is sparse and may be unverified, so confirm tags and diff history directly when pinning a version.
How does the user-scoped cache key suffix work in laravel-modelcache?
By default, cache keys are suffixed with the authenticated user ID, so a value written during one user's request is invisible to guests, other users, console commands, and queued jobs. You can override cacheNameSuffix() to return an empty string and share values across users. That is a one-line change that turns a performance feature into a cross-user data exposure risk if you apply it to genuinely per-user data, so classify each value as user-scoped or shared before the first pull request.
Can I use laravel-modelcache as an Eloquent query cache for models and collections?
No. Despite mentions of Eloquent query caching in the package description, the reviewed behavior is that it is not a query cache and is not intended for storing models or collections. It is designed for small per-model scalars such as a playback position, a wizard step, a last-viewed tab, or a memoized stat block. For query result caching, use Laravel's own Cache::remember around the query or a repository-layer cache instead.
How do I configure the cache store and lifetime for model cache entries?
Set MODEL_CACHE_STORE to choose which Laravel cache driver the package uses, and MODEL_CACHE_LIFETIME to set the TTL, which defaults to one week. Any Laravel cache driver works, but avoid volatile stores like array or file for values you treat as authoritative since they are lost on deploy or flush. You can also use the CacheProfile policy object to centralize per-model TTL and store decisions.
What happens when MODEL_CACHE_ENABLED is set to false?
Setting MODEL_CACHE_ENABLED to false silently disables the package with no error or warning. Every read path should therefore supply a working default, for example modelCached($key, $default), so the kill switch does not become an outage switch. Treat the flag as a safety valve and make sure your tests cover the cache-off path.
How do I test code that uses the ModelCache trait and facade?
Run your test suite against the array cache store so each test starts with a clean, isolated cache, and clear keys between tests that share state. Assert both the cache-hit path and the fallback default path, especially with MODEL_CACHE_ENABLED turned off. Because keys are user-scoped by default, also cover guest, console, and queued-job contexts where the user suffix differs.
Is foxws/laravel-modelcache safe for production, and what are the alternatives?
The code surface is small and the blast radius is bounded by your call sites, but the maturity signals are weak: few GitHub stars, no known dependents, and single-maintainer provenance. Adopt it with a pin, vendor it if possible, and budget for a fork; the exit cost is a use statement per model plus the keys you created. If that risk is unacceptable, plain Cache::remember calls or caching in your repository/service layer achieve similar results without adding a dependency.
Does laravel-modelcache work in queued jobs and Artisan console commands?
It works, but remember that cache keys are suffixed with the authenticated user ID by default, so user-scoped values written during a web request are invisible from a queued job or console command. Either pass the user context explicitly or use a shared suffix for genuinely non-user data. Also make sure the store you configure persists across workers and deploys.
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.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource