Skip to main content

CacheRepository

Trait CacheRepository 

Source
pub trait CacheRepository:
    Send
    + Sync
    + Debug
    + 'static {
    // Required methods
    fn name(&self) -> &str;
    fn get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<CacheEntry>, CamelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn set<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        value: CacheEntry,
        ttl: Option<Duration>,
    ) -> Pin<Box<dyn Future<Output = Result<(), CamelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn peek_stale<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<CacheEntry>, CamelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn invalidate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), CamelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn clear<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), CamelError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn stats(&self) -> CacheStats { ... }
}
Expand description

Pluggable cache backend.

Implementations MUST be Send + Sync + 'static and propagate all backend failures as Err(CamelError) (Contract C1).

Required Methods§

Source

fn name(&self) -> &str

A human-readable name for this cache backend.

Source

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

Retrieve a value by key.

Returns Ok(None) if the key is absent or expired. All backend failures MUST be returned as Err(CamelError).

Source

fn set<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, value: CacheEntry, ttl: Option<Duration>, ) -> Pin<Box<dyn Future<Output = Result<(), CamelError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Store a value with an optional TTL.

The implementation computes expires_at from ttl and stores it in the CacheEntry. If ttl is None, the entry has no expiry.

Source

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

Peek at a stale (expired but not yet evicted) entry.

Returns Ok(None) if the key is absent or not yet expired.

Source

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

Remove a specific key from the cache.

Source

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

Remove all entries from the cache.

Provided Methods§

Source

fn stats(&self) -> CacheStats

Return current cache statistics.

Default implementation returns zeroed stats.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§