Class: CodeToQuery::Performance::IntentCache

Inherits:
Cache
  • Object
show all
Defined in:
lib/code_to_query/performance/cache.rb

Overview

Intent parsing cache specifically for NLP results

Constant Summary

Constants inherited from Cache

Cache::DEFAULT_TTL, Cache::MAX_CACHE_SIZE

Instance Method Summary collapse

Methods inherited from Cache

#clear, #delete, #get, #hit_rate, #set, #stats

Constructor Details

#initialize(config = {}) ⇒ IntentCache

Returns a new instance of IntentCache.



198
199
200
# File 'lib/code_to_query/performance/cache.rb', line 198

def initialize(config = {})
  super(config.merge(max_size: 500)) # Smaller cache for intents
end

Instance Method Details

#cache_intent(prompt, schema_hash, allow_tables, intent) ⇒ Object



202
203
204
205
# File 'lib/code_to_query/performance/cache.rb', line 202

def cache_intent(prompt, schema_hash, allow_tables, intent)
  cache_key = build_intent_key(prompt, schema_hash, allow_tables)
  set(cache_key, intent, ttl: 1800) # 30 minutes
end

#get_cached_intent(prompt, schema_hash, allow_tables) ⇒ Object



207
208
209
210
# File 'lib/code_to_query/performance/cache.rb', line 207

def get_cached_intent(prompt, schema_hash, allow_tables)
  cache_key = build_intent_key(prompt, schema_hash, allow_tables)
  get(cache_key)
end