Skip to main content

StorageBackend

Trait StorageBackend 

Source
pub trait StorageBackend:
    Send
    + Sync
    + 'static {
    type Key: Serialize + DeserializeOwned + Hash + Eq + Clone + Send + Sync;
    type Value: Serialize + DeserializeOwned + Clone + Send + Sync;
    type Metadata: Serialize + DeserializeOwned + Clone + Send + Sync;

    // Required methods
    fn save<'life0, 'life1, 'async_trait>(
        &'life0 self,
        entries: &'life1 HashMap<Self::Key, Vec<CacheEntry<Self::Key, Self::Value, Self::Metadata>>>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn load<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<HashMap<Self::Key, Vec<CacheEntry<Self::Key, Self::Value, Self::Metadata>>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn remove<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 Self::Key,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + 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<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn contains<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 Self::Key,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn size_bytes<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn compact<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait for cache storage backends

Required Associated Types§

Source

type Key: Serialize + DeserializeOwned + Hash + Eq + Clone + Send + Sync

Key type for the storage

Source

type Value: Serialize + DeserializeOwned + Clone + Send + Sync

Value type for the storage

Source

type Metadata: Serialize + DeserializeOwned + Clone + Send + Sync

Metadata type for entries

Required Methods§

Source

fn save<'life0, 'life1, 'async_trait>( &'life0 self, entries: &'life1 HashMap<Self::Key, Vec<CacheEntry<Self::Key, Self::Value, Self::Metadata>>>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Save entries to storage

Source

fn load<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<HashMap<Self::Key, Vec<CacheEntry<Self::Key, Self::Value, Self::Metadata>>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Load entries from storage

Source

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

Remove entries for a specific key

Source

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

Clear all entries from storage

Provided Methods§

Source

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

Check if storage contains a key

Source

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

Get approximate size of storage in bytes

Source

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

Compact storage (optional operation for backends that support it)

Implementors§