hyperf/model-cache
Hyperf model-cache adds automatic caching for Hyperf ORM models, reducing repeated database queries and speeding up reads. It integrates with model events for cache invalidation and supports configurable TTL and cache stores.
prefix let each service or tenant be purged independently. This supports launch decisions about sharing a Redis instance across services and environments without one team's flush evicting another's data.MODEL_CACHE_ENABLE=false, which degrades findFromCache to find) means a cache-related outage has a one-flag rollback. That materially lowers the severity class of the decision to adopt.composer required into a Laravel app. If the estate is Laravel, treat it as a reference design for genealabs/laravel-model-caching — the patterns map almost 1:1 — and make the adoption decision on the Laravel equivalent. Choosing this package is effectively a framework decision.Consider it when:
paginate(), count(), or aggregates (use hyperf/cache there).Cache::forget() calls, and the team will route all mutations through hydrated models (save(), delete(), destroy()).Look elsewhere when:
DB::transaction() where a backfill can read an uncommitted row.Model::query()->where(...)->update(), increment()/decrement() on the builder, upsert(), raw DB::update(). These are the number-one source of stale data here and require manual invalidation discipline the team may not sustain.findFromCache() builds from cached attributes and does not run global scopes, so a delete path that skipped an event keeps serving the row.mget).HandlerInterface seam yourself. Small stars is not disqualifying in-framework — it does mean "buy" here is really "buy from the framework vendor."On v3.2.3 specifically: patch-level, no stated breaking changes, no deprecations, no new capability. It is a maintenance signal (the project is alive and patching), not a feature signal. Do not let it shift roadmap priority or trigger an upgrade scramble — pin ^3.2 and run it through the normal dependency cycle.
For executives (one paragraph): We can absorb a meaningful spike in read traffic on our data-heavy pages without new infrastructure by adding a caching layer that stays automatically in sync with our data — a configuration and dependency change rather than a re-architecture, with a one-flag rollback if anything goes wrong. The main risk is stale data if we cache the wrong things, so we would scope it to content and catalogue reads first and explicitly exclude money-, stock-, and permission-critical paths. Two caveats: the package under review targets the Hyperf framework, so if we remain on Laravel we should adopt the equivalent library rather than this one; and its public community footprint is small, so the realistic posture is "adopt the framework vendor's component and keep the handler layer as our extension seam."
For engineering (short): query-result caching tied to model events, with lifecycle-based invalidation instead of hand-written keys. Reads are explicit and opt-in at the call site (findFromCache, findFromCacheMany) — the trait does not hijack find(), so adoption is incremental and reversible per endpoint. Before we adopt: (1) confirm framework fit — Hyperf only; (2) agree a per-model TTL and key-prefix policy, plus an explicit deny-list of models that must never be cached; (3) audit write paths for builder-level bypasses and decide the invalidation-after-commit pattern for transactional writes; (4) namespace prefix per app/env/service so staging can never flush production; (5) bind ArrayHandler in tests so suites don't touch Redis. Latest release is a patch bump with no documented breaking changes or features — upgrade on the normal cycle, not urgently.
Definition of success, first 30 days: a measurable drop in database load and p95 latency on the hot endpoints we cache, with no increase in stale-data incidents. Instrument hit rate and the specific mc:* key space before launch, run a warm-up command post-deploy to avoid a cold-cache stampede, and review the deny-list once traffic data is in. If a "cache bug" appears, flipping the kill switch tells us within minutes whether the read path is fine and the problem is invalidation — that triage speed is part of the value.
How can I help you explore Laravel packages today?