Skip to main content

Module server

Module server 

Source
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 ServerCache static 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 invalidate the 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§

ServerCache
An in-process cache of up to capacity entries, each kept for ttl after it was fetched. Declare one as a static, where it is needed; it is built on first use: