-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: move cache to common, cache public key * fix: missing import * refactor: public key cache only needs one key * refactor: workspace deps * feat: tracing calls in public_key cache flow * refactor: init cache in AuthPublicKey::new * fix: clippy
- Loading branch information
Showing
12 changed files
with
112 additions
and
75 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::{ | ||
sync::{Arc, RwLock}, | ||
time::Duration, | ||
}; | ||
use ttl_cache::TtlCache; | ||
|
||
pub trait CacheManagement: Send + Sync { | ||
type Value; | ||
|
||
fn get(&self, key: &str) -> Option<Self::Value>; | ||
fn insert(&self, key: &str, value: Self::Value, ttl: Duration) -> Option<Self::Value>; | ||
fn invalidate(&self, key: &str) -> Option<Self::Value>; | ||
} | ||
|
||
pub struct CacheManager<T> { | ||
pub cache: Arc<RwLock<TtlCache<String, T>>>, | ||
} | ||
|
||
impl<T> CacheManager<T> { | ||
pub fn new(capacity: usize) -> Self { | ||
let cache = Arc::new(RwLock::new(TtlCache::new(capacity))); | ||
|
||
Self { cache } | ||
} | ||
} | ||
|
||
impl<T: Send + Sync + Clone> CacheManagement for CacheManager<T> { | ||
type Value = T; | ||
|
||
fn get(&self, key: &str) -> Option<Self::Value> { | ||
self.cache | ||
.read() | ||
.expect("cache lock should not be poisoned") | ||
.get(key) | ||
.cloned() | ||
} | ||
|
||
fn insert(&self, key: &str, value: T, ttl: Duration) -> Option<Self::Value> { | ||
self.cache | ||
.write() | ||
.expect("cache lock should not be poisoned") | ||
.insert(key.to_string(), value, ttl) | ||
} | ||
|
||
fn invalidate(&self, key: &str) -> Option<Self::Value> { | ||
self.cache | ||
.write() | ||
.expect("cache lock should not be poisoned") | ||
.remove(key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod auth; | ||
pub mod cache; | ||
pub mod headers; | ||
pub mod metrics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
mod auth_layer; | ||
mod cache; | ||
|
||
pub mod latest; |