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
Eloquent Autocache

Eloquent Autocache Laravel Package

wddyousuf/eloquent-autocache

Automatic, self-invalidating Eloquent query caching. Add one trait and reads are cached transparently while any write flushes the model's cache. Uses cache tags or per-model versioning, so it works on every store.

View on GitHub
Deep Wiki
Context7

Automatic Eloquent model query caching for Laravel with self-flushing on create, update, and delete.

Frequently asked questions about Eloquent Autocache
How do I install wddyousuf/eloquent-autocache in a Laravel app?
Run composer require wddyousuf/eloquent-autocache. The service provider and AutoCache facade are auto-discovered, so no manual registration is required. Optionally publish the config file with php artisan vendor:publish --tag=autocache-config to create config/autocache.php. After that you only need to add the Cacheable trait to the models you want cached.
Which Laravel and PHP versions does eloquent-autocache support?
The package requires PHP 8.1 or newer and supports Laravel 10, 11, 12, and 13. On Laravel 13 it works with the default serializable_classes setting because it only caches arrays and scalars, so you do not need to allow-list models or stdClass. Pin the package version and confirm compatibility against your exact Laravel and PHP versions before rolling out.
How does eloquent-autocache invalidate cached queries on create, update and delete?
Any write to a cached model flushes that model's cache automatically, including bulk operations, raw writes, and event-suppressing quiet writes. When the cache store supports tags, invalidation is immediate and targeted; on other stores the package falls back to a per-model version counter. This means you never have to call a cache-clearing method manually in your controllers or observers.
Which cache store should I use in production with AutoCache?
Redis or Memcached are the best fit because tag support gives immediate, targeted invalidation. File, database, and array stores still work through the per-model version counter fallback, but invalidation is less precise and can cause broader cache churn. Avoid the array store in production since it is request-local. Also make sure every web and queue node shares the same cache layer.
Can I disable caching for a specific model or query?
Yes. AutoCache supports an auto mode and an opt-in mode, plus per-query controls and per-model overrides in the configuration. That lets you enable the trait on a single pilot model first and leave everything else uncached. Removing the trait or disabling the setting is a straightforward rollback if you need to turn caching off during an incident.
Does eloquent-autocache work with Laravel Octane and queue workers?
The README documents an Octane section and the package is designed for normal Laravel request lifecycles, but long-running workers change how state and invalidation behave. You should explicitly verify cache flushing across Octane workers and queued writes in your own environment. Pin versions of Laravel, PHP, the cache driver, and Octane, then run load and invalidation tests before trusting it in production.
How do I test that cached queries are properly invalidated in my application?
The README includes a testing section, but the practical approach is to write regression tests around your own write paths. Cover bulk updates and upserts, raw SQL through Eloquent, quiet writes, transaction rollbacks, and queued jobs, then assert that a fresh read returns the new data. Because the package has limited external validation, your test suite is the real safety net, so also watch cache hit ratio and stale-read reports in your pilot.
Is AutoCache safe to use in a multi-tenant application?
Cache keys must be scoped per tenant, and the package does not remove that responsibility from you. If tenant scoping is missing or inconsistent, a tenant could read another tenant's cached rows, so verify how keys combine model, query, and tenant identifiers in your setup. Run a dedicated test that switches tenants in the same process and confirms no cross-tenant hits.
What TTL should I set, and does AutoCache support stale-while-revalidate?
The package documents a stale-while-revalidate feature and per-model configuration, so you can pick a conservative TTL for your pilot model and tune from measured hit ratios. Use a shorter TTL as a safety net for any write path you are not fully confident about. Behavior when the cache store is unavailable is not spelled out in the README excerpt, so test that failure mode explicitly before depending on it.
How does eloquent-autocache compare with other Laravel query caching packages, and is it maintained?
The README includes a comparison with other packages and the project is MIT licensed with no warranty. It is early-stage, with roughly 41 stars and no dependents, so external validation is limited and API stability or maintainer responsiveness is not guaranteed. Treat it as a tactical performance optimization for proven read-heavy models rather than a platform-wide default, and pin the version you validate.
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.
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin