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§
Sourcefn 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,
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.
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.