highlevel_api/storage/
memory.rs1use crate::{auth::token::TokenData, error::Result, storage::SessionStorage};
2use async_trait::async_trait;
3use std::collections::HashMap;
4use tokio::sync::RwLock;
5
6pub struct MemoryStorage {
8 data: RwLock<HashMap<String, TokenData>>,
9}
10
11impl MemoryStorage {
12 pub fn new() -> Self {
13 Self {
14 data: RwLock::new(HashMap::new()),
15 }
16 }
17}
18
19impl Default for MemoryStorage {
20 fn default() -> Self {
21 Self::new()
22 }
23}
24
25#[async_trait]
26impl SessionStorage for MemoryStorage {
27 async fn get(&self, key: &str) -> Result<Option<TokenData>> {
28 Ok(self.data.read().await.get(key).cloned())
29 }
30
31 async fn set(&self, key: &str, token: TokenData) -> Result<()> {
32 self.data.write().await.insert(key.to_string(), token);
33 Ok(())
34 }
35
36 async fn delete(&self, key: &str) -> Result<()> {
37 self.data.write().await.remove(key);
38 Ok(())
39 }
40}