feat(cache): two-tier cache + per-node request coalescing - #1
Merged
Conversation
… with per-type TTLs
…via TOSS_CACHE_L2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Market-data calls hit a rate-limited upstream. Bursts of identical requests (the common case when several agents ask for the same quote) each cost an upstream call, and slow-changing data was re-fetched as aggressively as live quotes.
What
A two-tier read-through cache in front of the Toss Open API, with per-node single-flight coalescing.
get(key, loader)is atomic per key, so concurrent identical requests on a node collapse to one upstream load. L1 honors the caller's per-type TTL via Caffeine variable expiry, so a single node caches correctly with no Redis deployed.TOSS_CACHE_L2=true). Adds cross-instance sharing. Any Redis error degrades to a cache miss and never breaks a tool call.005930,000660and000660,005930share one entry.Tools still return the raw upstream JSON string — the cache is transparent to the MCP contract.
Scope
L1 single-flight is per-node. Cross-node request coalescing is not implemented; the shared L2 narrows but does not eliminate the concurrent-miss window across instances. HTTP (Streamable) transport is deferred to Phase 2.5.
Testing
18 tests.
RedisL2CacheITuses Testcontainers (disabledWithoutDocker = true) and is skipped locally without a Docker daemon — this PR run is its first execution on a Docker-enabled runner.MarketDataCacheTestMarketDataCacheTtlTestTicker)MarketDataServiceTestRedisL2CacheDegradeTestRedisL2CacheITCacheWiringTestL2Cachebean across all three property modes