Skip to content

feat(cache): pluggable CacheManager via devslab.kit.cache.type (ADR 0002 PR 1)#32

Merged
jlc488 merged 2 commits into
mainfrom
feat/cache-infra
May 31, 2026
Merged

feat(cache): pluggable CacheManager via devslab.kit.cache.type (ADR 0002 PR 1)#32
jlc488 merged 2 commits into
mainfrom
feat/cache-infra

Conversation

@jlc488

@jlc488 jlc488 commented May 31, 2026

Copy link
Copy Markdown
Contributor

First of 4 PRs implementing ADR 0002 (now Accepted). Lands the cache infrastructure + the type switch; Redis serialization, menu-cache migration, and sample-app/docs follow.

What

devslab.kit.cache:
  type: in-memory   # none | in-memory | redis  (default in-memory)
  ttl: PT10M
  key-prefix: "devslab:"
  • New modules devslab-kit-cache-api (CacheNames) + devslab-kit-cache-core (CacheType, CacheProperties, CacheAutoConfiguration).
  • type=noneNoOpCacheManager; type=in-memory (default) → ConcurrentMapCacheManager.
  • @EnableCaching turned on but guarded by @ConditionalOnMissingBean(CacheManager) — a consumer who manages caching themselves always wins.
  • Redis stays compileOnly in -cache-core → never a transitive dependency; in-memory default keeps the zero-dependency path (ADR 0002 §4).
  • RedisCacheConfiguration is a guarded no-op scaffold here; the real RedisCacheManager + safe-default-typing JSON serialization land in PR 2 with a real-Redis Testcontainers round-trip test (serialization is the risk, so it gets its own tested PR).

Tests

CacheAutoConfigurationTest (ApplicationContextRunner): default in-memory · explicit in-memory · none→NoOp · disabled→no bean · consumer-bean-wins · property binding. Registered as a plain user config rather than AutoConfigurations.of(...) because SB4 splits that helper's package across two jars ("package not visible") — noted in the test javadoc.

Verification

./gradlew build --no-daemon green (fresh, CI parity); cache modules confirmed in the build graph + autoconfigure dependency.

Sign-off note

@EnableCaching on-by-default was approved in the ADR thread (guarded). No behaviour change for existing consumers — default is in-memory, same single-node semantics as today's menu cache (which migrates onto this in PR 3).

jlc488 added 2 commits May 31, 2026 11:56
…002 PR 1)

Introduces the cache infrastructure from ADR 0002 (now Accepted). A consumer
flips one property to choose the backing store; the kit owns the CacheManager
and turns on Spring's caching annotations so the consumer's own @Cacheable
methods just work.

New modules
- devslab-kit-cache-api: CacheNames constants (kit-internal cache names).
- devslab-kit-cache-core: CacheType (none/in-memory/redis), CacheProperties
  (devslab.kit.cache.*), CacheAutoConfiguration.

CacheAutoConfiguration
- type=none → NoOpCacheManager; type=in-memory (default) → ConcurrentMapCacheManager.
- @EnableCaching turned on, but guarded by @ConditionalOnMissingBean(CacheManager)
  so a consumer who manages caching themselves always wins.
- RedisCacheConfiguration is imported but a deliberate no-op scaffold in this PR
  (guards in place); the real RedisCacheManager + safe-default-typing JSON
  serialization land in PR 2 with a real-Redis Testcontainers round-trip test.
- Redis is compileOnly in -cache-core, so it never becomes a transitive
  dependency — the in-memory default stays zero-dependency (ADR 0002 §4).

Wiring
- settings.gradle.kts: include the two new modules.
- autoconfigure depends on -cache-api/-cache-core.

Tests
- CacheAutoConfigurationTest (ApplicationContextRunner): default in-memory,
  explicit in-memory, none→NoOp, disabled→no bean, consumer-bean-wins,
  property binding. Registered as a plain user config (not AutoConfigurations.of)
  because SB4 splits that helper's package across two jars; see the test javadoc.

Docs: ADR 0002 flipped Proposed → Accepted with the implementation note.
PR 1's settings include() edit never made it to disk (it was in a cancelled
tool batch I mistakenly thought had applied), so the two new cache modules were
absent from the build. Local --no-daemon passed off a stale daemon/cache state;
CI's fresh checkout failed with 'Project :devslab-kit-cache-api could not be
found'. Added the includes; verified with daemon stopped + ./gradlew build
--no-daemon (BUILD SUCCESSFUL, fresh).
@jlc488
jlc488 merged commit 07bd08a 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