Class: MCP::Tool::Schema::ValidationCache
- Inherits:
-
Object
- Object
- MCP::Tool::Schema::ValidationCache
- Defined in:
- lib/mcp/tool/schema.rb
Overview
Metaschema validation depends only on schema content, so a given schema never needs to be validated more than once. Caching the result lets repeated (e.g. dynamically rebuilt) schemas skip the costly traversal.
Constant Summary collapse
- DEFAULT_MAX_SIZE =
1000
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(max_size: DEFAULT_MAX_SIZE) ⇒ ValidationCache
constructor
A new instance of ValidationCache.
- #store(key) ⇒ Object
- #validated?(key) ⇒ Boolean
Constructor Details
#initialize(max_size: DEFAULT_MAX_SIZE) ⇒ ValidationCache
Returns a new instance of ValidationCache.
15 16 17 18 19 |
# File 'lib/mcp/tool/schema.rb', line 15 def initialize(max_size: DEFAULT_MAX_SIZE) @max_size = max_size @entries = {} @mutex = Mutex.new end |
Instance Method Details
#clear ⇒ Object
33 34 35 |
# File 'lib/mcp/tool/schema.rb', line 33 def clear @mutex.synchronize { @entries.clear } end |
#store(key) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/mcp/tool/schema.rb', line 25 def store(key) @mutex.synchronize do @entries.delete(key) @entries[key] = true @entries.shift while @entries.size > @max_size end end |
#validated?(key) ⇒ Boolean
21 22 23 |
# File 'lib/mcp/tool/schema.rb', line 21 def validated?(key) @mutex.synchronize { @entries.key?(key) } end |