Context
The current market/position cache is in-process (Arc<RwLock>). This means:
- Cache is lost on every server restart (cold boot hits Stellar RPC with N markets x M calls)
- Running multiple API replicas behind a load balancer means each has a stale independent cache
Replacing with Redis gives persistence across restarts and a shared cache across replicas.
Implementation
Add a Redis client (using deadpool-redis) as an AppState dependency.
Cache keys and TTLs:
- markets_list -> 30s
- market:{address} -> 15s
- positions:{account} -> 10s
- orders:{account} -> 10s
- stats -> 60s
Fallback: if Redis is unreachable on startup, fall back to in-memory cache and log a warning (degraded mode, not a hard failure).
Env vars: REDIS_URL (default redis://localhost:6379), REDIS_CACHE_ENABLED=true|false.
Acceptance criteria
Context
The current market/position cache is in-process (Arc<RwLock>). This means:
Replacing with Redis gives persistence across restarts and a shared cache across replicas.
Implementation
Add a Redis client (using deadpool-redis) as an AppState dependency.
Cache keys and TTLs:
Fallback: if Redis is unreachable on startup, fall back to in-memory cache and log a warning (degraded mode, not a hard failure).
Env vars: REDIS_URL (default redis://localhost:6379), REDIS_CACHE_ENABLED=true|false.
Acceptance criteria