Class: RailsAiBridge::CacheWarmer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/cache_warmer.rb

Overview

Pre-populates the introspection cache during Rails boot.

Calling .warm triggers a full introspection pass so that the first MCP tool call returns instantly from cache rather than blocking on a cold introspection. Errors are logged and swallowed — warming is best-effort and must never prevent the app from starting.

Class Method Summary collapse

Class Method Details

.warm(app = nil) ⇒ void

This method returns an undefined value.

Warms the full introspection cache for app.

Parameters:

  • app (Rails::Application) (defaults to: nil)


16
17
18
19
20
21
# File 'lib/rails_ai_bridge/cache_warmer.rb', line 16

def warm(app = nil)
  app ||= AppScope.current_app
  ContextProvider.fetch(app)
rescue StandardError => error
  log_warning("cache warming failed: #{error.message}")
end

.warm_sections(sections, app = nil) ⇒ void

This method returns an undefined value.

Warms individual section caches for the given introspector keys.

Parameters:

  • sections (Array<Symbol>)

    introspector keys to warm

  • app (Rails::Application) (defaults to: nil)


28
29
30
31
32
33
34
35
# File 'lib/rails_ai_bridge/cache_warmer.rb', line 28

def warm_sections(sections, app = nil)
  app ||= AppScope.current_app
  sections.each do |section|
    ContextProvider.fetch_section(section, app)
  rescue StandardError => error
    log_warning("section #{section} warming failed: #{error.message}")
  end
end