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 = Rails.application) ⇒ void

This method returns an undefined value.

Warms the full introspection cache for +app+.

Parameters:

  • app (Rails::Application) (defaults to: Rails.application)


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

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

.warm_sections(sections, app = Rails.application) ⇒ 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: Rails.application)


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

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