from __future__ import annotations from dataclasses import dataclass from uuid import UUID from .config import CacheSettings @dataclass(frozen=True, slots=True) class ContentCacheKeys: settings: CacheSettings @property def base(self) -> str: return f"{self.settings.key_prefix}:content:{self.settings.key_version}" @staticmethod def _norm(v: str) -> str: v = v.strip() if not v: raise ValueError("cache key component must not be blank") return "-".join(v.split()) def active_modules(self) -> str: return f"{self.base}:modules:active" def module_contents(self, module_id: UUID) -> str: return f"{self.base}:module:{module_id}:contents" def module_template_contents(self, *, module_id: UUID, template_code: str) -> str: return f"{self.base}:module:{module_id}:template:{self._norm(template_code)}:contents" def module_template_details(self, *, module_id: UUID, template_code: str) -> str: return f"{self.base}:module:{module_id}:template:{self._norm(template_code)}:details" def template_definitions(self, template_code: str) -> str: return f"{self.base}:template:{self._norm(template_code)}:definitions" def content_detail(self, content_id: UUID) -> str: return f"{self.base}:content:{content_id}:detail" def content_pattern(self, content_id: UUID) -> str: return f"{self.base}:content:{content_id}:*" def module_pattern(self, module_id: UUID) -> str: return f"{self.base}:module:{module_id}:*" def template_pattern(self, template_code: str) -> str: return f"{self.base}:*:template:{self._norm(template_code)}:*" def lock_for(self, key: str) -> str: return f"{self.settings.key_prefix}:lock:{key}"