wasm_cache/
item.rs

1use crate::CacheKey;
2use async_trait::async_trait;
3use std::{error::Error, fmt::Debug};
4
5/// Represents some action that can be cached.
6///
7/// The action has one associated type called [`Value`]. This is the value of data that this action
8/// returns. That data is cached, so that future invocations of this item can reuse the previously
9/// computed data.
10///
11/// The cached data here can be anything, but typically is a network request. The resulting value
12/// is typically the response type of the network request.
13#[async_trait(?Send)]
14pub trait CacheItem<M = ()>: CacheKey<M> + Clone + Ord {
15    type Value: Clone + Debug + PartialEq + 'static;
16    type Error: Debug + Error + 'static;
17
18    async fn send(&self) -> Result<Self::Value, Self::Error>;
19
20    fn superset(&self) -> Vec<Self> {
21        vec![]
22    }
23}