Class: RailsAiBridge::Registry::ProviderRequestScope
- Inherits:
-
Object
- Object
- RailsAiBridge::Registry::ProviderRequestScope
- Defined in:
- lib/rails_ai_bridge/registry/provider_request_scope.rb
Overview
Per-invocation memo for context-provider tool results.
The scope lives for one MCP tool invocation (one rails_get_provider_context
call). It is not a process-wide cache, Rails controller request cache, or
cross-request HTTP cache. The tool that creates the scope is responsible
for discarding it after the call completes.
Instance Method Summary collapse
-
#clear ⇒ Hash
Removes all cached entries.
-
#fetch_or_store(provider_name, tool_name, args_key: nil) ⇒ Object
Returns the cached result for the given provider and tool, or yields the block and stores the result for subsequent lookups.
-
#initialize ⇒ ProviderRequestScope
constructor
A new instance of ProviderRequestScope.
Constructor Details
#initialize ⇒ ProviderRequestScope
Returns a new instance of ProviderRequestScope.
12 13 14 |
# File 'lib/rails_ai_bridge/registry/provider_request_scope.rb', line 12 def initialize @cache = {} end |
Instance Method Details
#clear ⇒ Hash
Removes all cached entries.
34 |
# File 'lib/rails_ai_bridge/registry/provider_request_scope.rb', line 34 delegate :clear, to: :@cache |
#fetch_or_store(provider_name, tool_name, args_key: nil) ⇒ Object
Returns the cached result for the given provider and tool, or yields
the block and stores the result for subsequent lookups. The optional
args_key distinguishes same-name tool calls with different arguments.
24 25 26 27 28 29 |
# File 'lib/rails_ai_bridge/registry/provider_request_scope.rb', line 24 def fetch_or_store(provider_name, tool_name, args_key: nil) key = [provider_name, tool_name, args_key] return @cache[key] if @cache.key?(key) @cache[key] = yield end |