aboutsummaryrefslogtreecommitdiffstats
path: root/src/cache.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cache.rs')
-rw-r--r--src/cache.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/cache.rs b/src/cache.rs
index 0e8fd4d..a6f25fa 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -1,5 +1,14 @@
-use std::{future::Future, time::*, collections::HashMap, hash::Hash};
+use std::future::Future;
+use std::time::*;
+use std::collections::HashMap;
+use std::hash::Hash;
+use std::sync::Arc;
+use std::pin::Pin;
+
+use tokio::sync::RwLock;
+
use reqwest::StatusCode;
+
#[derive(Debug)]
pub struct AsyncCache<K, V, F> {
func: F,
@@ -66,3 +75,7 @@ where
self.get(key).await.cloned()
}
}
+
+pub type CacheFuture<Output> = Pin<Box<(dyn Future<Output = Result<Output, (StatusCode, &'static str)>> + Send + Sync)>>;
+pub type CacheGetter<Output> = fn(&String) -> CacheFuture<Output>;
+pub type Cache<Output> = Arc<RwLock<AsyncCache<String, Output, CacheGetter<Output>>>>;