Skip to main content

insert_cached

Function insert_cached 

Source
pub fn insert_cached<V>(
    cache: &dyn Cache,
    key: &str,
    value: V,
    ttl: Option<Duration>,
)
where V: Clone + Serialize + Send + Sync + 'static,
Expand description

Serde-aware insert: store the value both in-memory and as JSON bytes.

Calls Cache::insert_value (for in-process backends like Moka) and Cache::insert_raw_bytes (for cross-replica backends like Redis). This is what the #[cached] macro uses so that the stored value is accessible both within the same process and on other replicas.

ttl is forwarded verbatim to Cache::insert_raw_bytes so backends like Redis can apply a native entry expiry (e.g. SET EX). In-process backends (Moka) manage TTL via the per-function static cache instance and ignore this parameter.