pub trait ValueLoader: Send + Sync {
    type Value: ValueBounds;

    // Required method
    fn load<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str
    ) -> Pin<Box<dyn Future<Output = Result<Self::Value, Box<dyn Error + Send + Sync + 'static>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

ValueLoader loads a value for a particular key - which can be potentially expensive. Groupcache is responsible for calling load on whichever node is responsible for a particular key and caching that value. ValueLoader::Values will be cached by groupcache according to passed options.

ValueLoader::Value cached by groupcache must satisfy ValueBounds.

If you want to load resources of different types, your implementation of load may distinguish desired type by prefix of key and return an enum as ValueLoader::Value. This is a deviation from original groupcache library which implemented separate groups and consumers of the library could have multiple implementation of ValueLoader.

Required Associated Types§

source

type Value: ValueBounds

Value is a type returned by load, see ValueBounds.

Required Methods§

source

fn load<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<Self::Value, Box<dyn Error + Send + Sync + 'static>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§