atrium_common/types/cached/
impl.rs

1#[cfg(not(target_arch = "wasm32"))]
2mod moka;
3#[cfg(target_arch = "wasm32")]
4mod wasm;
5
6use std::future::Future;
7use std::hash::Hash;
8
9#[cfg(not(target_arch = "wasm32"))]
10pub use self::moka::MokaCache as CacheImpl;
11#[cfg(target_arch = "wasm32")]
12pub use self::wasm::WasmCache as CacheImpl;
13
14use super::CacheConfig;
15
16#[cfg_attr(not(target_arch = "wasm32"), trait_variant::make(Send))]
17pub trait Cache {
18    type Input: Hash + Eq + Sync + 'static;
19    type Output: Clone + Sync + 'static;
20
21    fn new(config: CacheConfig) -> Self;
22    fn get(&self, key: &Self::Input) -> impl Future<Output = Option<Self::Output>>;
23    fn set(&self, key: Self::Input, value: Self::Output) -> impl Future<Output = ()>;
24}