Skip to content

ADR-005: In-process caches, evicted on a schedule

Status: Accepted (origin not recorded; documented 2026-11-06)

Context

Prices, currency lists and API keys are read on nearly every request, and the underlying sources are slow or rate-limited. A cache tier (Redis) was never introduced, and the platform runs a single replica set of each service in Ctlq.

Decision

Each service caches in its own process with Spring's ConcurrentMapCacheManager, and evicts on a fixed interval with @Scheduled:

Service Caches Eviction
core currencies, currentPrices_with_quote, currentChanges, currentAths 5 min / 5 s / 5 s / 30 min
portfolio currencies, prices, changes 5 min / 15 s / 10 min
findata currencies, externalApiKeys 5 min / 60 min
worker currencies, externalApiKeys 5 min / 60 min
webservice currencies, currentPrices, currentChanges 5 min

No shared cache, no invalidation protocol, no distributed lock.

Alternatives considered

  • Redis as a shared cache. Would make eviction consistent across instances and survive restarts. Rejected so far on operational cost: another stateful component in the cluster for data that is cheap to recompute.
  • No cache. Would put a Feign call plus a database read on every price lookup; unacceptable for the UI's polling paths.
  • Per-service TTL tuning only. This is what is practised — the intervals differ per cache, and that difference is intentional.

Consequences

  • Caches diverge across processes by design. With more than one replica, two users can see different prices for a few seconds. Correctness never depends on the cache: the database is the source of truth, the cache only borrows time.
  • A stale-data report is usually an eviction interval, not a bug. Check the interval in the owning service before instrumenting anything.
  • A cache is only correct if something evicts it. A cache key registered but never evicted, or an eviction key that matches no cache, is a silent staleness bug — both have happened here. Keep registration and eviction in the same file so they are read together.
  • Moving to Redis later is a change to this ADR, not a refactor: it needs an invalidation design and a decision about what may be cached across services.