mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 10:27:46 +08:00
perf: reduce gateway db pressure under load
This commit is contained in:
@@ -1,18 +1,21 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use aether_cache::ExpiringMap;
|
||||
use tokio::sync::{Mutex, MutexGuard};
|
||||
|
||||
const MAX_ENTRIES: usize = 512;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct SystemConfigCache {
|
||||
entries: ExpiringMap<String, Option<serde_json::Value>>,
|
||||
load_guard: Mutex<()>,
|
||||
}
|
||||
|
||||
impl Default for SystemConfigCache {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
entries: ExpiringMap::new(),
|
||||
load_guard: Mutex::new(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +29,10 @@ impl SystemConfigCache {
|
||||
self.entries.insert(key, value, ttl, MAX_ENTRIES);
|
||||
}
|
||||
|
||||
pub(crate) async fn load_guard(&self) -> MutexGuard<'_, ()> {
|
||||
self.load_guard.lock().await
|
||||
}
|
||||
|
||||
pub(crate) fn clear(&self) {
|
||||
self.entries.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user