dashboard-nanobot/backend/services/cache_service.py

28 lines
959 B
Python
Raw Normal View History

2026-03-31 04:31:47 +00:00
from typing import Optional
from core.cache import cache
def _cache_key_bots_list() -> str:
2026-03-31 06:56:31 +00:00
return "bot:list:v3"
2026-03-31 04:31:47 +00:00
def _cache_key_bot_detail(bot_id: str) -> str:
2026-03-31 06:56:31 +00:00
return f"bot:detail:v3:{bot_id}"
2026-03-31 04:31:47 +00:00
def _cache_key_bot_messages(bot_id: str, limit: int) -> str:
return f"bot:messages:list:v2:{bot_id}:limit:{limit}"
def _cache_key_bot_messages_page(bot_id: str, limit: int, before_id: Optional[int]) -> str:
cursor = str(int(before_id)) if isinstance(before_id, int) and before_id > 0 else "latest"
return f"bot:messages:page:v2:{bot_id}:before:{cursor}:limit:{limit}"
def _cache_key_images() -> str:
return "images:list"
def _invalidate_bot_detail_cache(bot_id: str) -> None:
cache.delete(_cache_key_bots_list(), _cache_key_bot_detail(bot_id))
def _invalidate_bot_messages_cache(bot_id: str) -> None:
cache.delete_prefix(f"bot:messages:{bot_id}:")
def _invalidate_images_cache() -> None:
cache.delete(_cache_key_images())