tdm_server_rust/cache/
manga_name_cache.rs1use crate::{app::AppState, entity::manga::MangaSimpleVo};
14use std::sync::Arc;
15use std::time::Duration;
16
17const CACHE_KEY: &str = "manga_tran_names";
19
20pub type MangaTranNameCache = moka::future::Cache<String, Arc<Vec<MangaSimpleVo>>>;
22
23pub fn new_manga_tran_name_cache() -> MangaTranNameCache {
27 let ttl_secs = std::env::var("MANGA_NAME_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_manga_names(state: &AppState) {
40 state.manga_tran_name_cache.invalidate(CACHE_KEY).await;
41 state.manga_ori_name_cache.invalidate(CACHE_KEY).await;
42}
43
44pub fn cache_key() -> &'static str {
46 CACHE_KEY
47}