darkghosthunter/rememberable-query
A Laravel package that caches Eloquent query results and remembers them across requests, with automatic invalidation on model changes. Drop-in trait for faster repeated queries.
Cache::remember(...) closures, hand-roll cache keys, or reach for staudenmeir/laravel-caching-query. This package demonstrates a one-line ergonomic (Post::remember(60)->where(...)->get()) that removes that boilerplate, which is a real developer-experience win on read-heavy endpoints.Illuminate\Cache. The PM decision is to adopt the pattern, not the dependency: spec a first-party trait behind our own namespace, with our key-prefix, TTL, and invalidation conventions baked in.file and database cache drivers don't support tags), model-event-driven invalidation, or blunt TTLs. This is the real roadmap conversation this package surfaces.Consider the approach when:
Look elsewhere — or rather, do not adopt this specific package — because:
Builder has changed meaningfully since 2022; assume it needs verification and likely patching before it runs on a current version.remember() trait is the wrong abstraction — prefer explicit repository-level caching or Laravel's Cache::flexible/Cache::remember at a service boundary where you control the key and the flush.remember() risks cross-tenant leakage through key collisions — a class of bug worth avoiding entirely.To executives: We found a small open-source package that solves a real and common problem — making database query results cheap to cache. The idea is sound and worth copying; the package itself is abandoned, unmaintained since 2022, and used by nobody. My recommendation is a short internal build (roughly half a day of engineering) rather than taking on a dead dependency. Expected outcome is fewer database round-trips on our read-heavy screens, no added supply-chain risk, and no licence or vendor exposure.
To engineering: This is the one-line query-caching ergonomic we keep re-writing by hand. Don't take the dependency — it's archived, unpatched, and untested against current Laravel. Instead, let's lift the pattern into a RememberableQuery trait we own: remember($ttl, $tags = null) on the Eloquent builder, delegating to Cache::tags() when the store supports it, defaulting to a namespaced cache key derived from the SQL and bindings, and a documented posture that cached results may hold stale model attributes. We own the invalidation contract, we control the key namespace, and we can add an escape hatch (->fresh(), a withoutRemember() scope) from day one. Estimate: one spike to confirm the builder hook, one PR to ship, plus tests for tag flushing and tenancy-scoped keys.
How can I help you explore Laravel packages today?