You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
748 B
Rust
33 lines
748 B
Rust
use crate::data::memcache::{Indexable, MemCache};
|
|
use crate::model::{Account, AccountId};
|
|
|
|
pub struct MemAccountDataSource {
|
|
cache: MemCache<AccountId, Account>,
|
|
}
|
|
|
|
impl MemAccountDataSource {
|
|
pub fn new() -> MemAccountDataSource {
|
|
MemAccountDataSource {
|
|
cache: MemCache::new(),
|
|
}
|
|
}
|
|
|
|
pub async fn by_id(&self, id: AccountId) -> Option<Account> {
|
|
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<AccountId> for Account {
|
|
fn get_id(&self) -> AccountId {
|
|
self.id
|
|
}
|
|
}
|