replyflow-rag / services /cache_service.py
Qurrah's picture
REFINE: replace inventory_cache with instant_reply_cache for consistency and clarity in cache management
efd039f
Raw History Blame Contribute Delete
1.17 kB
from repositories.social_account import list_channel_identifiers_for_workspace
from repositories.workspace import get_workspace_id_by_slug
from core.cache import credentials_cache, instant_reply_cache, product_result_cache
def clear_all_caches() -> None:
instant_reply_cache.clear()
credentials_cache.clear()
product_result_cache.clear()
def clear_product_result_cache_for_slug(brand_slug: str) -> int:
workspace_id = get_workspace_id_by_slug(brand_slug)
channel_identifiers = list_channel_identifiers_for_workspace(workspace_id)
def matches(key: str) -> bool:
return any(
key.startswith(f"query:{identifier}:")
for identifier in channel_identifiers
)
return instant_reply_cache.delete_matching(matches) + product_result_cache.delete_matching(matches)
def clear_instant_reply_cache() -> None:
instant_reply_cache.clear()
def clear_instant_reply_cache_for_identifier(channel_identifier: str) -> int:
return (
instant_reply_cache.delete_matching(lambda key: channel_identifier in key)
+ product_result_cache.delete_matching(lambda key: channel_identifier in key)
)