use crate::core::{ActorBackend, StorageError}; use moka::future::Cache; use std::sync::Arc; use std::time::Duration; pub struct ActorIdStore { backend: Arc, cache: Cache, } impl ActorIdStore { pub fn new(backend: Arc, cache_capacity: u64, cache_ttl: Duration) -> Self { Self { backend, cache: Cache::builder() .max_capacity(cache_capacity) .time_to_live(cache_ttl) .build(), } } pub async fn get(&self, did: &str) -> Result { if let Some(id) = self.cache.get(did).await { return Ok(id); } let id = self.backend.get_actor_id(did).await?; self.cache.insert(did.to_string(), id).await; Ok(id) } pub async fn clear_cache(&self) { self.cache.invalidate_all(); } }