Watson Rememberable
Simple, expressive query caching for Laravel Eloquent - cache any query's results with a single remember() call.
Repository Health
Technical Analysis
Watson Rememberable adds transparent query caching to Laravel’s Eloquent ORM. By mixing a single trait into your models, you gain a remember() method on the query builder that caches a query’s results in your configured Laravel cache store for a chosen number of seconds, returning the cached rows on subsequent identical queries instead of hitting the database.
The package extends Laravel’s own query builder rather than replacing it, so caching composes naturally with your existing where clauses, joins, and eager loads. Cache keys are generated automatically from the query, and helpers let you tag, prefix, choose a cache driver, or flush cached results when data changes.
What You Get
- A Rememberable trait that swaps in a cache-aware query builder for a model
- remember(), rememberForever(), and dontRemember() methods on the query builder
- Automatic, query-derived cache keys with optional custom keys and prefixes
- Cache tagging, per-query cache-driver selection, and manual flushCache() support
- Seamless composition with existing Eloquent where/join/eager-load clauses
Common Use Cases
- Caching expensive aggregate or reporting queries for a fixed TTL
- Reducing database load for frequently repeated read queries
- Serving reference/lookup data that changes rarely from cache
- Tagging cached queries so related entries can be flushed together on writes
Under The Hood
Architecture - The package is two files. src/Rememberable.php is a trait that overrides Eloquent’s newBaseQueryBuilder() to return the package’s own src/Query/Builder.php, optionally pre-seeding remember duration, tags, prefix, and driver from model properties. Builder.php extends Laravel’s Illuminate\Database\Query\Builder and wraps its get()/pluck() execution in a cache remember/rememberForever closure keyed by a hash of the generated SQL and bindings.
Tech Stack - PHP 8.2+ depending only on illuminate/database and illuminate/support (^11|^12|^13), so it targets modern Laravel. It reuses Laravel’s CacheManager, meaning any configured cache store (Redis, Memcached, file, array) works transparently.
Code Quality - The codebase is intentionally tiny and focused, decorating rather than reimplementing the query builder, which keeps the maintenance surface small. It provides no bundled test suite in the shipped source tree, relying on its narrow scope and Laravel’s own builder guarantees; the documented method annotations on the trait keep IDE/static-analysis support intact.
API Design - The public surface is a single fluent method, remember($seconds), plus ergonomic variants (rememberForever, dontRemember, cacheTags, cacheDriver, prefix, flushCache). Because it composes with normal query-builder chains, developers add caching to an existing query by inserting one call, which makes the learning curve minimal.