Skip to content

docs(adr): pluggable distributed cache (ADR 0002)#31

Merged
jlc488 merged 1 commit into
mainfrom
docs/adr-distributed-cache
May 31, 2026
Merged

docs(adr): pluggable distributed cache (ADR 0002)#31
jlc488 merged 1 commit into
mainfrom
docs/adr-distributed-cache

Conversation

@jlc488
Copy link
Copy Markdown
Contributor

@jlc488 jlc488 commented May 31, 2026

Design-only PR (like #28 was for bootstrap). Captures the distributed-cache decision before any code.

The idea (your call from this session)

A consumer flips one property to turn the cache from in-memory to distributed (Redis), and never touches serialization. Their own @Cacheable methods just work across replicas.

devslab.kit.cache:
  type: in-memory   # none | in-memory | redis  (default in-memory)
  ttl: PT10M
  key-prefix: "devslab:"

Why

  • Today's menu cache is a ConcurrentHashMapbreaks on >1 replica (stale on every node but the writer until TTL lapses).
  • Every Spring Boot consumer otherwise re-solves distributed caching themselves, and the part that bites everyone is serialization (Serializable requirement, SerializationException, hand-configuring JSON + safe default-typing). A platform starter should decide that once.

What the ADR proposes

  1. devslab.kit.cache.type switch → CacheManager bean (none / in-memory / redis), each conditionally wired; consumer's own CacheManager always wins.
  2. Redis JSON serialization owned by the kitGenericJackson2JsonRedisSerializer + a safe default-typing ObjectMapper (no LaissezFaireSubTypeValidator). This is the headline value.
  3. New -cache-api / -cache-core modules; Redis stays optional & non-transitive (in-memory default keeps zero-dependency simple path).
  4. The menu cache becomes the first consumer of the shared CacheManager — one cache story, and it stops being a multi-replica bug.
  5. Consumers get distributed @Cacheable on their own code for free.

Plan (4 PRs)

cache-api/core + autoconfig → Redis path + serialization (real-Redis Testcontainers round-trip test) → migrate menu cache → sample-app(type=redis on the compose Redis it already starts) + docs.

Targeted for v0.1.0 (decided: cache first, then release).

Sign-off needed

  1. Approve the type switch shape + property names.
  2. Approve the 4-PR split.
  3. OK to turn on @EnableCaching by default (guarded by @ConditionalOnMissingBean)?

Once you're happy I'll flip Status → Accepted and start PR 1.

Design for a devslab.kit.cache.* block with a type switch (none / in-memory /
redis) where flipping one property turns a single-node cache into a correct
distributed one — and the kit owns the Redis JSON serialization so consumers
never touch it or hit SerializationException. The existing hand-rolled menu
cache becomes the first consumer of the shared CacheManager; the consumer's own
@Cacheable methods get distributed caching for free. Design-only; bilingual.
@jlc488 jlc488 merged commit e522623 into main May 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant