ghostcompiler/laravel-model-caching
Automatically caches Eloquent model queries and invalidates them whenever a model is created, updated, or deleted, so repeated database reads are served from cache. A drop-in trait for Laravel models with minimal configuration and no code changes required.
composer require ghostcompiler/laravel-model-caching. v1.0.0 is the first tagged/stable release, so pin it ("^1.0") and treat the linked changelog as the only release artifact — there is no migration guide because this is the baseline.php artisan vendor:publish --tag=model-caching (confirm the tag/name against the package README, since the release notes don't enumerate it).file and database stores do not support cache tags and will silently weaken invalidation behavior.Cachable trait to the models you want cached (verify the exact namespace from the README — it is typically a Traits\Cachable import). After that, normal Eloquent calls are cached transparently; you don't rewrite queries.Post::latest()->take(10)->get() is cached as a unit. Eager-loaded relations (with('author', 'comments')) are cached as part of the result set, so relation access after retrieval is free.->disableCache()) for admin views, exports, or strongly consistent reads (e.g., right after a write in the same request).$cachePrefix (avoid key collisions across models/tenants) and a cooldown/TTL setting (often $cacheCooldownSeconds) to prevent stampedes on hot keys.Cache::tags(...)->flush()).array) or disable the trait behavior in phpunit.xml so tests assert database state, not stale cache. Add at least one test that exercises invalidation end-to-end.$cachePrefix; otherwise tag-scoped invalidation can bleed across tenants.Model::where(...)->update() / ->delete() do not fire Eloquent events, so automatic invalidation is skipped. Either iterate model instances or call the flush API immediately after.DB::afterCommit) to avoid caching pre-commit or rolling-back state.file/database stores, tag-based invalidation degrades or fails. Standardize on Redis in staging/prod and verify with a real invalidation test.refresh() / fresh() still hit the database. Don't assume these are cached; use them intentionally when you need guaranteed-fresh data.updateOrCreate / seeders. These can leave stale entries. Flush after running seeders, factories, or data migrations, and consider flushing in CI setup.$cachePrefix and the configured store.$cachePrefix, cooldown/TTL settings, and cache events/hooks rather than forking. If you need custom keys or selective invalidation, build it on the package's public flush/tag API.How can I help you explore Laravel packages today?