mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 10:27:46 +08:00
33 lines
762 B
Rust
33 lines
762 B
Rust
use std::time::Duration;
|
|||
|
|
|
||
|
|
use aether_cache::ExpiringMap;
|
||
|
|
|
||
|
|
const MAX_ENTRIES: usize = 512;
|
||
|
|
|
||
|
|
#[derive(Debug)]
|
||
|
|
pub(crate) struct SystemConfigCache {
|
||
|
|
entries: ExpiringMap<String, Option<serde_json::Value>>,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Default for SystemConfigCache {
|
||
|
|
fn default() -> Self {
|
||
|
|
Self {
|
||
|
|
entries: ExpiringMap::new(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl SystemConfigCache {
|
||
|
|
pub(crate) fn get(&self, key: &str, ttl: Duration) -> Option<Option<serde_json::Value>> {
|
||
|
|
self.entries.get_fresh(&key.to_string(), ttl)
|
||
|
|
}
|
||
|
|
|
||
|
|
pub(crate) fn insert(&self, key: String, value: Option<serde_json::Value>, ttl: Duration) {
|
||
|
|
self.entries.insert(key, value, ttl, MAX_ENTRIES);
|
||
|
|
}
|
||
|
|
|
||
|
|
pub(crate) fn clear(&self) {
|
||
|
|
self.entries.clear();
|
||
|
|
}
|
||
|
|
}
|