Skip to main content

CacheBackend

Trait CacheBackend 

Source
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 + Sync so the resolver can move backend handles across tokio::spawn task boundaries.
  • WASM — no Send/Sync requirement so backends backed by single-threaded handles (Rc<RefCell<...>> for idb::Database, js_sys::Function for callback bridges) implement the trait directly, without the unsafe impl Send + Sync workaround the previous unconditional bound forced.

Required Methods§

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Drop everything.

Provided Methods§

Source

fn shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Optional graceful shutdown (flush pending writes, close transactions). Default no-op.

Implementors§