tdm_server_rust/cache/
member_all_cache.rs1use crate::{app::AppState, entity::member::MemberCache};
14use std::sync::Arc;
15use std::time::Duration;
16
17const CACHE_KEY: &str = "member_all";
19
20pub type MemberAllCache = moka::future::Cache<String, Arc<Vec<MemberCache>>>;
22
23pub fn new_member_all_cache() -> MemberAllCache {
27 let ttl_secs = std::env::var("MEMBER_ALL_CACHE_SECS")
28 .ok()
29 .and_then(|v| v.parse().ok())
30 .unwrap_or(60);
31 moka::future::Cache::builder()
32 .time_to_live(Duration::from_secs(ttl_secs))
33 .build()
34}
35
36pub async fn invalidate_member_all(state: &AppState) {
40 state.member_all_cache.invalidate(CACHE_KEY).await;
41}
42
43pub fn member_all_cache_key() -> &'static str {
45 CACHE_KEY
46}