atrium_common/types/
cached.rs1pub mod r#impl;
2
3use std::fmt::Debug;
4use std::time::Duration;
5
6#[derive(Clone, Debug, Default)]
7pub struct CacheConfig {
8 pub max_capacity: Option<u64>,
9 pub time_to_live: Option<Duration>,
10}
11
12pub trait Cacheable<C>
13where
14 Self: Sized,
15{
16 fn cached(self, cache: C) -> Cached<Self, C>;
17}
18
19impl<T, C> Cacheable<C> for T {
20 fn cached(self, cache: C) -> Cached<Self, C> {
21 Cached::new(self, cache)
22 }
23}
24
25pub struct Cached<T, C> {
26 pub inner: T,
27 pub cache: C,
28}
29
30impl<T, C> Cached<T, C> {
31 pub fn new(inner: T, cache: C) -> Self {
32 Self { inner, cache }
33 }
34}