Invalidate llm suggestion cache on doc save

This commit is contained in:
shamoon
2025-04-21 13:04:01 -07:00
parent 767118fa8a
commit 377dcc39f5
2 changed files with 24 additions and 1 deletions

View File

@@ -122,7 +122,7 @@ def get_llm_suggestion_cache(
doc_key = get_suggestion_cache_key(document_id)
data: SuggestionCacheData = cache.get(doc_key)
if data and data.classifier_version == 1000 and data.classifier_hash == backend:
if data and data.classifier_hash == backend:
return data
return None
@@ -152,6 +152,19 @@ def set_llm_suggestions_cache(
)
def invalidate_llm_suggestions_cache(
document_id: int,
) -> None:
"""
Invalidate the LLM suggestions cache for a specific document and backend.
"""
doc_key = get_suggestion_cache_key(document_id)
data: SuggestionCacheData = cache.get(doc_key)
if data:
cache.delete(doc_key)
def get_metadata_cache_key(document_id: int) -> str:
"""
Returns the basic key for a document's metadata