genealabs/laravel-model-caching
A Laravel package that adds automatic query caching to Eloquent models. Use the provided trait to cache model queries, with cached results invalidated automatically when records are created, updated, or deleted, reducing database load with minimal code changes.
Architecture fit. Unchanged in shape: laravel-model-caching remains a transparent interception layer over Eloquent — cache keyed query result sets, invalidated from model events, no repository rewrite or read-model migration. It is still the right shape for read-heavy, low-write models and the wrong shape for high-write or cross-model derived state.
Two things in 13.2.0 change the architectural story materially:
Net: fit is better than before on bounded-staleness and worse than before on immediate upgrade cost.
Integration feasibility. High for a standard Laravel app on Redis, but the entry cost has risen and the upgrade gate is now the dominant line item rather than the invalidation inventory. Specifically:
protected $isCachable redeclaration and any trait rule naming Cachable::newBaseQueryBuilder (as or insteadof). Both are greppable and both should be a pre-merge check, because a class-load fatal is a hard outage on deploy.mike-bronner/laravel-model-caching where the prior assessment references genealabs/laravel-model-caching. Confirm the current Packagist name, whether the old name still resolves or is marked abandoned, and whether the namespace move changes your composer require line. A namespace/repo move is a supply-chain governance event for a TPM, not a cosmetic detail.php artisan modelCache:clear after deploy, because some changed queries retain old key text and could otherwise read entries written by the previous version. Skipping it opens a transient wrong-data window. Treat this as a deployment runbook step with an owner, not as advice.Technical risk.
newBaseQueryBuilder(), 13.1.11 and 13.2.0 spent multiple PRs fixing the regressions and collisions it caused. That is normal for an actively maintained package but argues against auto-upgrading across minor versions in production without a real-cache test run.Key questions. (revised)
DB::table(), bulk updates, imports, and third-party jobs writing the same tables?$isCachable and for trait rules naming Cachable::newBaseQueryBuilder? Both are class-load fatals.~13.2.0, or ^13.0? Given that minor versions have carried breaking changes, what is our justification for anything looser than a tilde?genealabs/laravel-model-caching → mike-bronner/laravel-model-caching a rename we need to action, and is there a maintained succession plan if upstream goes quiet?Stack fit. Unchanged: Laravel (multiple majors CI-tested), now PHP 8.3–8.5, tag-capable cache store with Redis as the de-risked default. Library, not a service — composer require, no runtime process, no schema change. 13.2.0 adds a configuration surface (global + per-model TTL) that fits naturally into existing config files rather than requiring code changes.
Migration path. Still incremental and reversible, but there are now two paths and they should not be conflated:
Path A — new adoption. Unchanged from the prior assessment, and strictly better than before because you start on 13.2.x with TTL available:
~13.2.0), caching disabled globally, cache store pointed at Redis.Path B — existing install upgrading. This is now the higher-risk path and needs its own runbook:
$isCachable declarations and for Cachable::newBaseQueryBuilder in as/insteadof rules. Fix before upgrade — these are class-load fatals.php artisan modelCache:clear immediately post-deploy. Do not skip; do not substitute cache:clear.modelCache:clear as a general "flush everything" — that behaviour is gone. Add php artisan cache:clear where whole-store flushing was actually intended.$cachePrefix: an open cool-down window ends early once at upgrade.There is still no big-bang migration and none should be attempted. Rollback per model remains a config flag.
Compatibility. Four axes to verify explicitly now, up from two:
Cachable with CTE or other traits defining newBaseQueryBuilder() are the specific population at risk from item 3. Enumerate them.Also confirm behaviour under queue workers, Octane/long-lived workers, and multi-tenant setups where keys must not collide across tenants — the $cachePrefix cooldown-key change in this release makes the multi-tenant path worth an explicit test. Testing approach: mirror the project's own pattern — Testbench plus a live Redis and Pest — because an array store masks tag and serialization behaviour and would have caught none of the bugs this release fixed.
Sequencing. (revised — step 0 is new and blocks everything)
0. Upgrade gate: PHP floor verification, $isCachable and trait-rule audit, pinned version decided, modelCache:clear added to the deploy runbook.
noeviction on a store shared with queues/sessions.For existing installs, step 0 comes before step 1, because the audit results may change scope.
Maintenance. Code-maintenance surface stays low; process maintenance goes up. The ongoing obligations are now three rather than two:
TTL partially relieves (b) by bounding the damage of a missed invalidation, but it does not remove the obligation — it converts a potential indefinite staleness incident into a shorter one.
Support. Still a single-maintainer project, now with a slightly better contributor base (two external contributors in this release, one first-time). The contribution discipline visible in the changelog — issue-first, numbered review points resolved in follow-up PRs, explicit regressions tracked — remains a genuinely strong signal for a package this size. Two offsets: bus factor is still one, and the release shows the package is willing to make breaking behavioural changes in a minor version, which raises the cost of being wrong about a fork. Budget for internal vendoring and name an internal owner; there is no commercial support path.
Scaling. Unchanged core story — Redis becomes a hard dependency on the read path, capacity must cover the hot working set plus headroom, and cache flush causes stampede. 13.2.0 improves two things and worsens one:
modelCache:clear from "wipe the whole Redis database when the prefix is empty" to "delete only this package's entries" removes a genuinely dangerous blast radius — particularly on a Redis instance shared with sessions and queues.modelCache:clear guarantees a deliberate cold-cache event on the upgrade deploy. Coordinate it with traffic levels, warm the hot set if you can, and stagger across instances. This is now a scheduled database-load event, not an incidental one.Failure modes. Rehearse these; each needs a named owner and a detection signal before rollout.
$isCachable or a stale Cachable::newBaseQueryBuilder trait rule. High severity, high detectability, cheap to prevent — grep in CI.modelCache:clear expecting a full flush now under-flushes. Symptom is a "stuck" cache after a manual intervention. Low severity, confusing.$cachePrefix cooldown-key change.Ramp-up. Roughly a day for an experienced Laravel engineer to install 13.2.x and get a pilot model working with TTL configured. One to three weeks for the team to build the invalidation inventory, wire observability, and roll out the first cohort responsibly. For an existing install, add one to two days for the audit, the trait-composition check, the modelCache:clear runbook change, and a scheduled cold-cache deploy window.
The organizational ramp-up remains the longer and more important half: teaching the team that reads may be cached, and adding cache-invalidation review to the change process. Now add a third habit: read this package's changelog as breaking-changes-only, and never take a minor bump on a Friday. Write the two or three paragraphs of internal documentation covering which models are cached, what the TTL policy is, and how to bypass the cache when debugging. Absent that, expect repeated incidents that look like application bugs — and now also expect at least one upgrade deploy where someone skips the cache clear.
How can I help you explore Laravel packages today?