use crate::config; use crate::db; use crate::model; use moka::sync::Cache; use std::sync::Arc; use std::time::{Duration, Instant}; #[derive(Clone)] pub struct AppState { pub storage: db::UserStorage, pub config: config::Config, pub cache: Arc, Instant)>>, } impl AppState { pub async fn new() -> anyhow::Result { let config = config::Config::new().await?; let user_storage = db::init_user_storage().await; let cache = Cache::builder() .max_capacity(10_000) // максимальное количество записей .time_to_live(Duration::from_secs(300)) // TTL 5 минут .build(); let state = AppState { storage: user_storage, config: config.clone(), cache: Arc::new(cache), }; Ok(state) } }