Trait Factory

Source
pub trait Factory<TKey: Clone + Send + Sync + 'static, TValue: Clone + Send + Sync + 'static, TError: Clone + Send + Sync + 'static>:
    Send
    + Sync
    + Clone
    + Debug
    + 'static {
    // Required method
    fn get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 TKey,
    ) -> Pin<Box<dyn Future<Output = Result<TValue, TError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

A trait for implementing value factories that can be used with FusionCache.

The factory is responsible for retrieving or generating values when they’re not in the cache. It must be cloneable and thread-safe since it might be called from multiple tasks.

§Type Parameters

  • TKey - The type of keys used in the cache
  • TValue - The type of values stored in the cache
  • TError - The type of errors that can occur during value generation

Required Methods§

Source

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

Retrieves or generates a value for the given key.

This method is called when a value is not found in the cache. It should implement the logic to fetch or generate the value.

§Arguments
  • key - The key for which to retrieve or generate the value

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§