From 4bec6679a8af2a2b5cb53610a80dece3b6d30bb4 Mon Sep 17 00:00:00 2001 From: alyx Date: Thu, 10 Aug 2023 03:10:54 -0400 Subject: lots of stuff. theming basically done, added some logging, frontend basically done. --- src/cache.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/cache.rs') diff --git a/src/cache.rs b/src/cache.rs index dfe23e7..631f900 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -11,7 +11,7 @@ impl AsyncCache where for<'a> F: FnMut(&'a K) -> Fut + 'a, K: Hash + PartialEq + Eq + Clone, - Fut: Future> + Fut: Future> + Send + Sync { pub fn new(interval: Duration, func: F) -> Self { Self{ @@ -22,8 +22,10 @@ where pub async fn get(&mut self, key: &K) -> Result<&V, (StatusCode, &'static str)> { if self.is_stale(&key) { + log::trace!(target: "lfm::cache", "MISS : interval = {:?}", self.interval); self.renew(&key).await } else { + log::trace!(target: "lfm::cache", "HIT : interval = {:?}", self.interval); Ok(&self.cache.get(&key).unwrap().1) } } @@ -37,7 +39,8 @@ where pub fn is_stale(&self, key: &K) -> bool { if let Some((last_update, _)) = self.cache.get(key) { let now = Instant::now(); - now < (*last_update + self.interval) + log::trace!(target: "lfm::cache", "Key exists, last update {:?} ago.", now - *last_update); + now > (*last_update + self.interval) } else { true } } @@ -48,6 +51,8 @@ where } else { None } } + + pub fn interval(&self) -> Duration { self.interval } } impl AsyncCache @@ -55,7 +60,7 @@ where for<'a> F: FnMut(&'a K) -> Fut + 'a, K: Hash + PartialEq + Eq + Clone, V: Clone, - Fut: Future> + Fut: Future> + Send + Sync { pub async fn get_owned(&mut self, key: &K) -> Result { self.get(key).await.cloned() -- cgit v1.2.3-54-g00ecf