Skip to main content

shared/infrastructure/cache/
adapters.rs

1use std::sync::Arc;
2
3use crate::domain::cache::CacheAdapter;
4
5use super::{in_memory::InMemoryAdapter, memcache::MemCacheAdapter, redis::RedisAdapter};
6
7pub struct CacheAdapters {
8    pub cache_adapter: Arc<dyn CacheAdapter>,
9}
10
11impl CacheAdapters {
12    pub fn memcached(client: memcache::Client) -> Self {
13        Self {
14            cache_adapter: Arc::new(MemCacheAdapter::new(client)),
15        }
16    }
17
18    pub fn redis(connection: redis::aio::ConnectionManager) -> Self {
19        Self {
20            cache_adapter: Arc::new(RedisAdapter::new(connection)),
21        }
22    }
23
24    pub fn in_memory(store: InMemoryAdapter) -> Self {
25        Self {
26            cache_adapter: Arc::new(store),
27        }
28    }
29}