29 lines
806 B
Rust
29 lines
806 B
Rust
use std::{sync::Arc, time::Duration};
|
|
|
|
use domain::entities::account::Account;
|
|
use lazy_static::lazy_static;
|
|
use library::config;
|
|
use moka::{
|
|
future::{Cache, CacheBuilder},
|
|
policy::EvictionPolicy,
|
|
};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct CacheAccount {
|
|
pub account: Arc<Account>,
|
|
pub token: Arc<String>,
|
|
}
|
|
|
|
lazy_static! {
|
|
pub static ref LOGIN_CACHE: Cache<String, Arc<CacheAccount>> = {
|
|
CacheBuilder::new(20480)
|
|
.name("login_cache")
|
|
.eviction_policy(EvictionPolicy::lru())
|
|
.time_to_live(Duration::from_secs(config!().jwt.expires as u64))
|
|
.eviction_listener(|key, value, cause| {
|
|
tracing::info!("login_cache evict key: {:?}, value: {:?}, cause: {:?}", key, value, cause);
|
|
})
|
|
.build()
|
|
};
|
|
}
|