2026-03-24 15:12:56 +08:00
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
|
|
use aether_cache::ExpiringMap;
|
|
|
|
|
|
2026-04-05 20:23:16 +08:00
|
|
|
use crate::control::GatewayControlAuthContext;
|
2026-03-24 15:12:56 +08:00
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
|
pub(crate) struct AuthContextCache {
|
|
|
|
|
entries: ExpiringMap<String, GatewayControlAuthContext>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AuthContextCache {
|
|
|
|
|
pub(crate) fn get_fresh(
|
|
|
|
|
&self,
|
|
|
|
|
cache_key: &str,
|
|
|
|
|
ttl: Duration,
|
|
|
|
|
) -> Option<GatewayControlAuthContext> {
|
|
|
|
|
self.entries.get_fresh(&cache_key.to_string(), ttl)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn insert(
|
|
|
|
|
&self,
|
|
|
|
|
cache_key: String,
|
|
|
|
|
auth_context: GatewayControlAuthContext,
|
|
|
|
|
ttl: Duration,
|
|
|
|
|
max_entries: usize,
|
|
|
|
|
) {
|
|
|
|
|
self.entries
|
|
|
|
|
.insert(cache_key, auth_context, ttl, max_entries);
|
|
|
|
|
}
|
2026-05-12 13:15:41 +08:00
|
|
|
|
|
|
|
|
pub(crate) fn clear(&self) {
|
|
|
|
|
self.entries.clear();
|
|
|
|
|
}
|
2026-03-24 15:12:56 +08:00
|
|
|
}
|