pub struct RTCache<K, T, CB, S>{ /* private fields */ }
Expand description
A read-through in-memory cache on top of MemoryCache
Instead of providing a put
function, RTCache requires a type which implements Lookup to
be automatically called during cache miss to populate the cache. This is useful when trying to
cache queries to external system such as DNS or databases.
Lookup coalescing is provided so that multiple concurrent lookups for the same key results only in one lookup callback.
Implementations§
Source§impl<K, T, CB, S> RTCache<K, T, CB, S>
impl<K, T, CB, S> RTCache<K, T, CB, S>
Sourcepub async fn multi_get<'a, I>(
&self,
keys: I,
ttl: Option<Duration>,
extra: Option<&S>,
) -> Result<Vec<(T, CacheStatus)>, Box<Error>>
pub async fn multi_get<'a, I>( &self, keys: I, ttl: Option<Duration>, extra: Option<&S>, ) -> Result<Vec<(T, CacheStatus)>, Box<Error>>
Same behavior as RTCache::get but for an arbitrary amount of keys.
If there are keys that are missing from the cache, multi_lookup
is invoked to populate the
cache before returning the final results. This is useful if your type supports batch
queries.
To avoid dead lock for the same key across concurrent multi_get
calls,
this function does not provide lookup coalescing.