Trait pingora_memory_cache::Lookup

source ·
pub trait Lookup<K, T, S> {
    // Required method
    fn lookup<'life0, 'life1, 'async_trait>(
        key: &'life0 K,
        extra: Option<&'life1 S>,
    ) -> Pin<Box<dyn Future<Output = Result<(T, Option<Duration>), Box<dyn ErrorTrait + Send + Sync>>> + Send + 'async_trait>>
       where K: 'async_trait,
             S: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Lookup defines the caching behavior that the implementor needs. The extra field can be used to define any additional metadata that the implementor uses to determine cache eligibility.

§Examples

use pingora_error::{ErrorTrait, Result};
use std::time::Duration;

struct MyLookup;

impl Lookup<usize, usize, ()> for MyLookup {
    async fn lookup(
        &self,
        _key: &usize,
        extra: Option<&()>,
    ) -> Result<(usize, Option<Duration>), Box<dyn ErrorTrait + Send + Sync>> {
        // Define your business logic here.
        Ok(1, None)
    }
}

Required Methods§

source

fn lookup<'life0, 'life1, 'async_trait>( key: &'life0 K, extra: Option<&'life1 S>, ) -> Pin<Box<dyn Future<Output = Result<(T, Option<Duration>), Box<dyn ErrorTrait + Send + Sync>>> + Send + 'async_trait>>
where K: 'async_trait, S: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Return a value and an optional TTL for the given key.

Object Safety§

This trait is not object safe.

Implementors§