Module: Blazer::Ai::SchemaCache

Defined in:
lib/blazer/ai/schema_cache.rb

Constant Summary collapse

SCHEMA_VERSION =
ENV.fetch("BLAZER_AI_SCHEMA_VERSION", 1).to_i

Class Method Summary collapse

Class Method Details

.fetch(connection, data_source_id: nil) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/blazer/ai/schema_cache.rb', line 6

def fetch(connection, data_source_id: nil)
  cache_key = build_cache_key(data_source_id)
  ttl = Blazer::Ai.configuration.schema_cache_ttl

  Rails.cache.fetch(cache_key, expires_in: ttl) do
    build_schema_string(connection)
  end
end

.invalidate(data_source_id: nil) ⇒ Object



15
16
17
18
# File 'lib/blazer/ai/schema_cache.rb', line 15

def invalidate(data_source_id: nil)
  cache_key = build_cache_key(data_source_id)
  Rails.cache.delete(cache_key)
end

.invalidate_allObject



20
21
22
23
24
25
# File 'lib/blazer/ai/schema_cache.rb', line 20

def invalidate_all
  # Pattern-based deletion if supported, otherwise noop
  if Rails.cache.respond_to?(:delete_matched)
    Rails.cache.delete_matched("blazer_ai:schema:*")
  end
end