use crate::data::memcache::{Indexable, MemCache}; use crate::model::{Account, AccountId}; pub struct MemAccountDataSource { cache: MemCache, } impl MemAccountDataSource { pub fn new() -> MemAccountDataSource { MemAccountDataSource { cache: MemCache::new(), } } pub async fn by_id(&self, id: AccountId) -> Option { self.cache.get(id).await.map(|arc| arc.as_ref().clone()) } pub async fn store(&self, account: Account) { self.cache.put(account).await } pub async fn delete(&self, id: AccountId) { self.cache.del(id).await; } } impl Indexable for Account { fn get_id(&self) -> AccountId { self.id } }