mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
perf(gateway): 为 dashboard 接口添加短时响应缓存
新增 DashboardResponseCache,对 stats/daily_stats/provider_status 三个接口按用户维度缓存 15-30 秒,减少重复数据库查询。
This commit is contained in:
28
apps/aether-gateway/src/cache/dashboard_response.rs
vendored
Normal file
28
apps/aether-gateway/src/cache/dashboard_response.rs
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use aether_cache::ExpiringMap;
|
||||
|
||||
const MAX_ENTRIES: usize = 256;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct DashboardResponseCache {
|
||||
entries: ExpiringMap<String, Vec<u8>>,
|
||||
}
|
||||
|
||||
impl Default for DashboardResponseCache {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
entries: ExpiringMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DashboardResponseCache {
|
||||
pub(crate) fn get(&self, key: &str, ttl: Duration) -> Option<Vec<u8>> {
|
||||
self.entries.get_fresh(&key.to_string(), ttl)
|
||||
}
|
||||
|
||||
pub(crate) fn insert(&self, key: String, value: Vec<u8>, ttl: Duration) {
|
||||
self.entries.insert(key, value, ttl, MAX_ENTRIES);
|
||||
}
|
||||
}
|
||||
2
apps/aether-gateway/src/cache/mod.rs
vendored
2
apps/aether-gateway/src/cache/mod.rs
vendored
@@ -1,10 +1,12 @@
|
||||
mod auth_api_key_last_used;
|
||||
mod auth_context;
|
||||
mod dashboard_response;
|
||||
mod direct_plan_bypass;
|
||||
mod scheduler_affinity;
|
||||
|
||||
pub(crate) use auth_api_key_last_used::AuthApiKeyLastUsedCache;
|
||||
pub(crate) use auth_context::AuthContextCache;
|
||||
pub(crate) use dashboard_response::DashboardResponseCache;
|
||||
pub(crate) use direct_plan_bypass::DirectPlanBypassCache;
|
||||
pub(crate) use scheduler_affinity::{
|
||||
SchedulerAffinityCache, SchedulerAffinitySnapshotEntry, SchedulerAffinityTarget,
|
||||
|
||||
Reference in New Issue
Block a user