pub trait CacheBackend: Send + Sync {
// Required methods
fn get<'life0, 'async_trait>(
&'life0 self,
key: u64,
) -> Pin<Box<dyn Future<Output = Option<CachedEntry>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn put<'life0, 'async_trait>(
&'life0 self,
key: u64,
entry: CachedEntry,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn invalidate<'life0, 'async_trait>(
&'life0 self,
key: u64,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn invalidate_by_tag<'life0, 'life1, 'async_trait>(
&'life0 self,
tag: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + 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<(), CacheError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided method
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Pluggable cache backend trait. ?Send on WASM mirrors the
DataSourceProvider / TransformMiddleware story so single-threaded
browser environments don’t need Send bounds.
The supertrait bound is cfg-gated:
- native (
not(target_arch = "wasm32")) —Send + Syncso the resolver can move backend handles acrosstokio::spawntask boundaries. - WASM — no Send/Sync requirement so backends backed by
single-threaded handles (
Rc<RefCell<...>>foridb::Database,js_sys::Functionfor callback bridges) implement the trait directly, without theunsafe impl Send + Syncworkaround the previous unconditional bound forced.
Required Methods§
Sourcefn get<'life0, 'async_trait>(
&'life0 self,
key: u64,
) -> Pin<Box<dyn Future<Output = Option<CachedEntry>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get<'life0, 'async_trait>(
&'life0 self,
key: u64,
) -> Pin<Box<dyn Future<Output = Option<CachedEntry>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Look up an entry. Backends may return None for “not present” OR
“present but failed to deserialize” — the resolver treats both as
cache miss and falls through to the next tier or the provider.
Sourcefn put<'life0, 'async_trait>(
&'life0 self,
key: u64,
entry: CachedEntry,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn put<'life0, 'async_trait>(
&'life0 self,
key: u64,
entry: CachedEntry,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Insert or replace an entry. Returns Err only on backend storage
failure (poisoned mutex, IndexedDB transaction failure, etc.) — TTL
math happens at get time, not put.
Sourcefn invalidate<'life0, 'async_trait>(
&'life0 self,
key: u64,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invalidate<'life0, 'async_trait>(
&'life0 self,
key: u64,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Remove a single entry. No-op if the key is absent.
Sourcefn invalidate_by_tag<'life0, 'life1, 'async_trait>(
&'life0 self,
tag: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn invalidate_by_tag<'life0, 'life1, 'async_trait>(
&'life0 self,
tag: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Remove every entry whose tags contain the given tag. Used by the
resolver’s invalidate_by_slug / invalidate_by_namespace APIs.