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 Cacheable Model Laravel Package

elipzis/laravel-cacheable-model

Add automatic select-query caching to any Laravel Eloquent model with a single trait. Configure TTL, prefixes, and unique identifiers per model, skip manual cache calls, and rely on automatic flushing for inserts, updates, and deletes. Works with Redis, memcached, and more.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit. The package is a trait-plus-QueryBuilder-override design: adding use Cacheable to a model swaps in CacheableQueryBuilder, which hashes the query signature and reads/writes results against the configured cache store. This is an attractive fit for Laravel shops wanting zero-call-site-change caching, because it preserves idiomatic Eloquent (Model::query()->where(...)->get()) and requires no refactor of repositories or controllers. Architecturally, though, it sits inside the ORM's query path rather than beside it — a deliberately invasive placement that makes correctness and performance depend on how faithfully the builder can reproduce a cache key from arbitrary query state. It is best understood not as a general caching layer but as a narrow optimization for a small number of read-heavy, slow-changing reference models.

Integration feasibility. Mechanically trivial: one composer require, one optional vendor:publish for config (TTL, prefix, identifier, logging), one trait import per model. Opt-out (withoutCache()) and manual invalidation (flushCache()) exist for escape hatches, and the package supports tagged caches with expiry cleanup (0.5.0) and per-model config overrides via getCacheableProperties(). The realistic effort is not installation but validation: confirming that every query shape your application actually issues (whereIn with raw Expressions, whereNull, aggregates, pagination, chunking, eager loads, exists(), raw selects) either caches correctly or falls through safely. Note the low adoption signals — 158 stars, zero dependents, single-maintainer cadence — which shift due diligence burden onto us.

Technical risk. The dominant risks are correctness and blast radius:

  • Key collision / stale-read risk. Key derivation from query builder state is heuristic by nature. History shows recurring edge-case fixes (whereIn with Expression in 0.4.1, whereNull undefined values key in 0.6.0). Each such bug class manifests as a wrong result returned to a user, not an error — the worst failure mode.
  • Invalidation completeness. "Automated cache flush on updates, inserts, deletions" only covers writes routed through Eloquent on the cacheable model. Raw SQL, other services, queue workers writing via DB::, and cross-model dependencies (e.g., cached Category results changing when Product rows change) will silently serve stale data. flushCache() exists but must be invoked by us — that is application logic the package cannot own.
  • Performance inversion. The README itself concedes the override "imposes a load and performance burden" on every query. On write-heavy or always-changing entities the package makes things measurably worse. Misapplying the trait broadly is an anti-pattern the docs explicitly warn against.
  • Framework coupling. The override shadows a core Laravel class; upgrades to Laravel 14+ will require the package to ship compatible releases first. Version bumps have lagged (L11 in 0.4.0, L12 in 0.5.0, L13 in 0.6.0) — acceptable but a hard gate on our upgrade calendar.
  • Ecosystem concentration. One or two active maintainers, no dependents, no vendor SLA. MIT license means we can fork, but we must be willing to.

Key questions.

  1. Which specific models are genuinely read-heavy and slow-changing, and what is their read:write ratio and tolerable staleness window?
  2. Are all writes to those tables routed through Eloquent on the same model, or do raw SQL / jobs / external services also mutate them?
  3. What is our cache backend (Redis vs. database vs. file), and does it support tagging where the package relies on it?
  4. What is our Laravel upgrade cadence, and are we comfortable gating it on a third-party release?
  5. Do we have contract/feature test coverage over the candidate models' query shapes to detect cache-key regressions?

Integration Approach

Stack fit. Requires Laravel 11–13 / PHP 8.3–8.5 per recent releases; assumes a real cache store (Redis or memcached strongly preferred over file/database, since this package multiplies cache operations per query and tagged-cache behavior matters). Fits a conventional Laravel monolith or modular monolith with a repository-or-Eloquent data layer. It does not fit architectures where data access is already abstracted behind a read-model/CQRS layer, or where an existing caching strategy (response cache, Redis-backed repository cache, Octane-aware caches) is already in place — layering this on top creates two competing invalidation authorities.

Migration path. Incremental and reversible:

  1. Install and publish config in a non-production environment; keep logging.enabled = true initially to observe hit/miss and key behavior.
  2. Select 1–3 candidate models with high read volume, low write frequency, and no cross-model dependency (e.g., countries, currencies, taxonomy, feature flags, static catalogs).
  3. Add the trait, set per-model TTL in getCacheableProperties() rather than relying on global defaults.
  4. Run the full existing test suite plus targeted feature tests asserting identical results with cache cold and warm.
  5. Ship behind a config flag, observe cache hit ratio and DB query volume for a release cycle before expanding.

Rollback is a one-line trait removal per model, which is a genuine strength for a TPM-managed rollout.

Compatibility. Watch for: query-builder features the package may not key correctly (subqueries, whereHas, unions, raw expressions, withCount); pagination and cursor()/chunk() paths where cached rows may be served inconsistently; multi-tenant scoping implemented via global scopes — a global scope that varies per request must be reflected in the cache key, and this is the single most likely production incident vector. Also confirm behavior under Laravel Octane, where long-lived workers plus cache state can produce surprising cross-request effects, and confirm the cache prefix isolates environments (staging vs. production) and tenants.

Sequencing.

  • Phase 0 (1 sprint): Spike — install, instrument logging, benchmark cold vs. warm query latency on one candidate model; document the exact query shapes in our codebase that touch it.
  • Phase 1: Production hardening of that single model; establish invalidation ownership (who calls flushCache(), and on what events) and add a test that fails if a write path bypasses Eloquent.
  • Phase 2: Expand to 2–3 more models only where Phase 0 metrics justify it; codify an allowlist of cacheable models in a config or code review rule.
  • Phase 3: Decide build-vs-buy — if the pattern proves valuable but the override semantics remain fragile, migrate to explicit repository-level caching with our own keys, using the package as a validated proof of which queries are worth caching.

Operational Impact

Maintenance. Low ongoing code maintenance, moderate-to-high cognitive maintenance: every engineer touching a cacheable model must understand that query semantics now include cache semantics. That is a real onboarding and code-review tax. Dependency maintenance is light but not zero — we inherit the maintainer's Laravel/PHP support cadence and must track it. Budget roughly one engineer-day per quarter for version-bump verification, plus incident time if a key-collision bug surfaces.

Support. No commercial support; MIT-licensed community package with a single primary maintainer and 158 stars. Support model is effectively self-support: read the changelog, read the source (small and readable), or fork. This is acceptable for a non-critical read optimization and unacceptable for anything on a revenue-critical or compliance-critical path. Do not place this in front of billing, permissions, or inventory-availability reads.

Scaling. Scales well horizontally for read-heavy workloads — the whole point is offloading the database, and Redis-backed stores extend that benefit across app servers. Vertical concerns: cache memory growth from many distinct query signatures (a query with high-cardinality whereIn values generates near-unique keys and near-zero hit rate — a silent waste of memory and CPU). Set TTLs conservatively, monitor key count and eviction rate, and be prepared to cap or exclude models that generate key sprawl. The per-query overhead is constant and small but universal across cacheable models, so the benefit only materializes where hit rates are high; instrument hit ratio rather than assuming it.

Failure modes.

  • Silent staleness — wrong data served with a 200 OK. Highest-severity, hardest to detect; mitigate with short TTLs, an explicit invalidation owner, and cross-model invalidation review.
  • Cache-key collision / unsupported query shape — history of edge-case fixes; mitigate with cold-vs-warm differential tests across real query shapes.
  • Cache backend outage — depends on package and Laravel cache behavior; verify the app degrades to database reads rather than erroring, and load-test with Redis unavailable.
  • Global-scope omission — tenant data leakage if a scope isn't in the key. Treat as a security review item before any multi-tenant rollout.
  • Upgrade blocker — Laravel major release arrives before a compatible package release; mitigate by pinning and tracking the maintainer's release cadence.

Ramp-up. For a competent Laravel engineer: under half a day to install, configure, and cache a first model; one to two days to build genuine confidence in key correctness and invalidation for that model. The docs are adequate for the happy path and thin on internals — expect engineers to read the query builder source to answer "will this query be cached correctly?" Overall ramp-up is fast, but trust ramps slower than usage, and the rollout plan should reflect that gap.

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