Expand description
In-process server caches: answers kept in the server’s memory and shared by every request. See the crate docs for when to use one.
Two ways in:
cache_shared(server = "5m")on a server function whose answer is the same for every visitor caches the whole function. The attribute checks the function looks visitor-independent.- A
ServerCachestatic caches anything else: part of a function (an outside API call behind a database check), or a per-user answer with the user’s id in the key.
§What these caches cannot do
- Know about writes. An entry lives until it expires. A per-user
answer cached here comes back unchanged right after that user’s own
edit, even though the client invalidated and refetched. Cache only
what may be stale for its whole TTL, or
invalidatethe entry in every mutation that changes it. - Span servers. Each process has its own copy. With several replicas, an eviction reaches only the one that handled the write.
Re-exports§
pub use moka;
Structs§
- Server
Cache - An in-process cache of up to
capacityentries, each kept forttlafter it was fetched. Declare one as astatic, where it is needed; it is built on first use: