CacheBackend

Trait CacheBackend 

Source
pub trait CacheBackend:
    Send
    + Sync
    + Clone
    + 'static {
    // Required methods
    fn get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<CacheRead>, CacheError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn set<'life0, 'async_trait>(
        &'life0 self,
        key: String,
        entry: CacheEntry,
        ttl: Duration,
        stale_for: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn invalidate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn get_keys_by_tag<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _tag: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, CacheError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn invalidate_by_tag<'life0, 'life1, 'async_trait>(
        &'life0 self,
        tag: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<usize, CacheError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn invalidate_by_tags<'life0, 'life1, 'async_trait>(
        &'life0 self,
        tags: &'life1 [String],
    ) -> Pin<Box<dyn Future<Output = Result<usize, CacheError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn list_tags<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, CacheError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}

Required Methods§

Source

fn get<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<CacheRead>, CacheError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetches a cached entry by key.

Returns Ok(None) when the backend does not have a value or the entry has expired.

Source

fn set<'life0, 'async_trait>( &'life0 self, key: String, entry: CacheEntry, ttl: Duration, stale_for: Duration, ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores an entry with a time-to-live and additional stale window.

Source

fn invalidate<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invalidates the cache entry for key, if present.

Provided Methods§

Source

fn get_keys_by_tag<'life0, 'life1, 'async_trait>( &'life0 self, _tag: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, CacheError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves all cache keys associated with a tag.

Returns an empty vector if tags are not supported by this backend.

Source

fn invalidate_by_tag<'life0, 'life1, 'async_trait>( &'life0 self, tag: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<usize, CacheError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invalidates all cache entries associated with a tag.

Returns the number of entries invalidated.

Source

fn invalidate_by_tags<'life0, 'life1, 'async_trait>( &'life0 self, tags: &'life1 [String], ) -> Pin<Box<dyn Future<Output = Result<usize, CacheError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invalidates all cache entries associated with multiple tags.

Returns the total number of entries invalidated (may include duplicates).

Source

fn list_tags<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, CacheError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists all currently indexed tags.

Returns an empty vector if tags are not supported by this backend.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§