feat: implement size-limited LRU cache for JSON Schema validation#845
Conversation
|
I've been following the architectural changes proposed in PR #749 by @tzolov. While that PR focuses on the extensibility of the validator through suppliers, this PR addresses a critical resource management issue in the current default implementation. Specifically, the existing I'm happy to rebase or adjust this PR to align with the new supplier patterns once #749 is merged. Let me know if you'd like me to integrate these resilience improvements into the new supplier structure! |
I noticed that the current
DefaultJsonSchemaValidatorimplementations (Jackson 2 and 3) were using an unboundedConcurrentHashMapfor schema caching, which could lead to memory leaks in long-running processes if exposed to a large number of dynamic schemas.This PR addresses the
TODOin both modules by:LinkedHashMap.generateCacheKeylogic to use a stable JSON representation of the schema instead of the defaulthashCode(), preventing potential collisions and ensuring cache hits are reliable regardless of map order.These changes significantly improve the resilience and resource management of the SDK when validating complex MCP tool outputs.