digdigdig3_station/
cache.rs1use std::time::Duration;
9
10use crate::rest_cache::RestCache;
11use digdigdig3::core::types::{AccountType, ExchangeId, Ticker};
12
13pub type TickerKey = (ExchangeId, AccountType, String);
14
15pub fn ticker_cache(ttl: Duration) -> RestCache<TickerKey, Ticker> {
17 RestCache::new(ttl)
18}
19
20#[derive(Debug, Clone)]
23pub struct CacheConfig {
24 pub enabled: bool,
25 pub ticker_ttl: Duration,
26}
27
28impl Default for CacheConfig {
29 fn default() -> Self {
30 Self { enabled: false, ticker_ttl: Duration::from_secs(1) }
31 }
32}
33
34impl CacheConfig {
35 pub fn on() -> Self {
36 Self { enabled: true, ticker_ttl: Duration::from_secs(1) }
37 }
38 pub fn ticker_ttl(mut self, ttl: Duration) -> Self {
39 self.ticker_ttl = ttl;
40 self
41 }
42}