Add AI cache clearing infrastructure

Add ClearAiCacheJob for async cache clearing with low priority. Extend Enrichable concern with clear_ai_cache methods to unlock AI-enriched attributes and delete AI enrichment records. Trigger automatic cache clearing when OpenAI model setting changes.
This commit is contained in:
eureka928
2026-01-26 09:46:20 +01:00
parent 8b3ebd7988
commit 46ab1d8373
3 changed files with 68 additions and 0 deletions

View File

@@ -80,6 +80,8 @@ class Setting < RailsSettings::Base
class << self
alias_method :raw_onboarding_state, :onboarding_state
alias_method :raw_onboarding_state=, :onboarding_state=
alias_method :raw_openai_model, :openai_model
alias_method :raw_openai_model=, :openai_model=
def onboarding_state
value = raw_onboarding_state
@@ -94,6 +96,18 @@ class Setting < RailsSettings::Base
self.raw_onboarding_state = state
end
def openai_model=(value)
old_value = raw_openai_model
self.raw_openai_model = value
if old_value != value && old_value.present?
Rails.logger.info("OpenAI model changed from #{old_value} to #{value}, clearing AI cache for all families")
Family.find_each do |family|
ClearAiCacheJob.perform_later(family)
end
end
end
# Support dynamic field access via bracket notation
# First checks if it's a declared field, then falls back to individual dynamic entries
def [](key)