Skip to main content

Module cache

Module cache 

Source
Expand description

TTL-based caching with stale-while-revalidate semantics.

This module provides a thread-safe cache with time-to-live (TTL) expiration and the ability to serve stale data during refresh failures.

§Clock

The cache uses tokio::time::Instant as its monotonic clock. In normal operation this is identical to std::time::Instant; when a test runs inside a #[tokio::test(start_paused = true)] runtime, the clock becomes virtual and can be advanced deterministically via tokio::time::advance, which keeps TTL unit tests fast and non-flaky.

Structs§

SingleValueCache
A single-value cache with TTL, useful for caching expensive one-off computations like bootstrap data.
TtlCache
Thread-safe TTL cache with stale-while-revalidate semantics.