pub trait CachePreloader:
Send
+ Sync
+ 'static {
// Required methods
fn predict(&self, accessed_key: &str) -> Vec<(String, u32)>;
fn warm(&self, key: &str);
}Expand description
Hook for predictive cache preloading.
ThingsCache calls CachePreloader::predict after every get_* access
(hit or miss) to ask “given that key X was just accessed, what should we
queue for background warming?” The returned (key, priority) pairs are
pushed into the cache’s priority queue via [ThingsCache::add_to_warming].
On each warming-loop tick, the cache picks the top-priority queued keys
and calls CachePreloader::warm for each. The implementor is expected
to fetch the data and populate the cache (typically by tokio::spawning
a task that calls back into cache.get_*(key, fetcher)). warm is
fire-and-forget — errors must be handled internally.
The trait is synchronous to stay dyn-compatible without async-trait.
Implementors that need async work should spawn it inside warm.