Expand description
§apiplant-cache
An optional Redis cache, for functions to use.
Nothing in the framework caches through it. Resources, permissions, hooks and the admin manifest behave identically whether or not a cache is configured, and that is deliberate: a cache in front of CRUD would have to guess when a row changes, and guessing wrong means serving stale data through an API that never said it might. What a cache is good for is the work a function does — a third-party response worth memoising, a rate-limit counter, a one-time token with a natural expiry — and that is work only the function author can invalidate correctly.
So the cache is exposed, deliberately, only through a function’s Context:
[cache]
url = "redis://127.0.0.1:6379"
prefix = "my-app:"if let Some(hit) = ctx.cache_get("rates:eur")? { return Ok(hit); }
let rates = fetch_rates()?;
ctx.cache_set("rates:eur", &rates, Some(900))?;§Failing soft
A cache that is down is not an outage. Every operation here returns a
Result, and the host reports failures to the function rather than to the
caller — a function that treats a miss and an error alike keeps working when
Redis is restarted, which is the whole point of the data being disposable.
Structs§
- Cache
- A connected cache, shared by every worker.
Enums§
- Cache
Error - What went wrong talking to the cache.
- Op
- One cache operation, as a function sends it over the ABI.