Skip to content

cache

triplum.utils.cache

Canonical JSON and SHA-256 content identity helpers; no storage or I/O.

canonical_json

canonical_json(obj: Any) -> str
Source code in src/triplum/utils/cache.py
10
11
def canonical_json(obj: Any) -> str:
    return json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False)

content_key

content_key(kind: str, payload: Any) -> str
Source code in src/triplum/utils/cache.py
14
15
16
17
18
19
def content_key(kind: str, payload: Any) -> str:
    h = hashlib.sha256()
    h.update(kind.encode())
    h.update(b"\0")
    h.update(canonical_json(payload).encode())
    return h.hexdigest()