Skip to main content

digdigdig3_station/
cache.rs

1//! Cache layer — Phase 1: a thin Station-level wrapper around
2//! `digdigdig3::core::rest_cache::RestCache` keyed by
3//! `(ExchangeId, AccountType, raw_symbol)` for `get_ticker`.
4//!
5//! Step 6+: extend with orderbook L1 TTL, symbol metadata, and warm-start from
6//! disk. See `docs/plans/station-architecture.md` §6.
7
8use std::time::Duration;
9
10use crate::rest_cache::RestCache;
11use digdigdig3::core::types::{AccountType, ExchangeId, Ticker};
12
13pub type TickerKey = (ExchangeId, AccountType, String);
14
15/// Build a default RestCache<TickerKey, Ticker> with the supplied TTL.
16pub fn ticker_cache(ttl: Duration) -> RestCache<TickerKey, Ticker> {
17    RestCache::new(ttl)
18}
19
20/// Configuration knobs the builder will accept in step 6+. For Phase 1 only
21/// `ticker_ttl` is consumed.
22#[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}