29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
from typing import Optional
|
|
from core.cache import cache
|
|
|
|
def _cache_key_bots_list() -> str:
|
|
return "bot:list:v3"
|
|
|
|
def _cache_key_bot_detail(bot_id: str) -> str:
|
|
return f"bot:detail:v3:{bot_id}"
|
|
|
|
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:list:v2:{bot_id}:")
|
|
cache.delete_prefix(f"bot:messages:page:v2:{bot_id}:")
|
|
|
|
def _invalidate_images_cache() -> None:
|
|
cache.delete(_cache_key_images())
|