Expand description
A single cache, keyed by string, values serialized as JSON - backed by
SQL-family storage (Config::cache_driver == "database", the default)
or Redis ("redis"), chosen at each call by [store]’s own dispatch.
See [sql_store]/[redis_store] for the two implementations, and
store.rs’s own doc comment for the dispatch shape.
Deliberately ships no in-memory driver - mirroring
larust_http::session’s own “no in-memory option in the public API”
stance (an in-memory cache is the same trap: it “works” in every manual
test, then silently starts missing on every deploy/restart). Laravel’s
own default (CACHE_STORE=database since Laravel 11) points the same
direction - the "redis" option here mirrors Laravel’s other common
production choice, not an in-memory one.
Functions§
- forget
- Removes
key, if present. Not an error to forget a key that was never set or has already expired. - get
- Returns
Ok(None)for a missing or expired key (an ordinary cache miss). A key that exists but whose stored JSON can’t be coerced intoT- e.g. reading a key back with an incompatible type than it wasputwith - is a caller bug, not a miss, so it surfaces asErr(AppError::Internal)rather than silently degrading toNonethe way Laravel’s own cache would. - put
- Stores
valueunderkey, serialized as JSON, expiring afterttl. Overwrites any existing entry under the same key (Laravel’s ownput()semantics - not an error to reuse a key). - remember
- Returns the cached value under
keyif present and unexpired; otherwise callsf, stores its result underkeyforttl, and returns it.fis a plain generic closure, not a trait method, so there’s no async-fn-in-traitsSendpitfall to work around here (seedocs/GOTCHAS.md). Implemented purely in terms ofget/putabove, so it needs no driver-specific logic of its own.