Skip to main content

CacheStore

Trait CacheStore 

Source
pub trait CacheStore:
    Send
    + Sync
    + 'static {
    // Required methods
    fn get<'a>(&'a self, key: &'a str) -> CacheFuture<'a, Option<CachedValue>>;
    fn put(
        &self,
        key: String,
        value: CachedValue,
        ttl_ms: u64,
    ) -> CacheFuture<'_, ()>;
    fn remove<'a>(&'a self, key: &'a str) -> CacheFuture<'a, bool>;

    // Provided method
    fn purge_expired(&self) -> usize { ... }
}
Expand description

Pluggable asynchronous response/data cache store (in-memory, Redis, Memcached, etc.).

Required Methods§

Source

fn get<'a>(&'a self, key: &'a str) -> CacheFuture<'a, Option<CachedValue>>

Looks up an unexpired CachedValue for key.

§Arguments
  • &'a self - Shared reference to self.
  • &'a str - Cache key.
§Returns
  • CacheFuture<'a, Option<CachedValue>> - Cached value when present and unexpired.
Source

fn put( &self, key: String, value: CachedValue, ttl_ms: u64, ) -> CacheFuture<'_, ()>

Inserts or replaces value under key with time-to-live ttl_ms.

§Arguments
  • String - Cache key.
  • CachedValue - Payload and metadata to cache.
  • u64 - Entry TTL in milliseconds.
§Returns
  • CacheFuture<'_, ()> - Completion future.
Source

fn remove<'a>(&'a self, key: &'a str) -> CacheFuture<'a, bool>

Removes a single key from the cache.

§Arguments
  • &'a self - Shared reference to self.
  • &'a str - Cache key to invalidate.
§Returns
  • CacheFuture<'a, bool> - true when an entry was removed.

Provided Methods§

Source

fn purge_expired(&self) -> usize

Evicts expired entries and returns the count removed.

§Returns
  • usize - Number of expired entries reclaimed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§