Add KeyValueResponseCacheStore for distributed client response caching - #4479
Merged
Conversation
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.
#4464 gave servers cache hints and #4450 taught the client to honor them — but the client's response cache is a per-process in-memory LRU, so a fleet of FastMCP proxy replicas can't share cache fills: every replica pays its own wire calls to warm the same listings. This adds
KeyValueResponseCacheStore, aResponseCacheStoreadapter over the sameAsyncKeyValueabstraction FastMCP already uses for its event store and OAuth state, so any py-key-value backend (Redis, memory, filetree) can back the SDK's client cache:Two clients sharing one backend serve each other's fills: the included distributed test has client A populate
tools/listand client B serve it with zero wire calls, while a distinct partition correctly misses. Stored values round-trip through a type-tagged envelope validated against an allowlist derived from the SDK's own cacheable-result registry — a forged or unknown tag in a shared store is a cache miss, never an import-by-name — and everyCacheKeyfield (method, params, partition, negotiated protocol, server arm) is folded into the storage key so entries can't collide across tenants or protocol eras.clear()is scoped to the adapter's own collection namespace and never touches other tenants.No
Clientsignature changes —CacheConfig(store=...)already flows through from #4450. The dependency is already core.Label: enhancements