diff --git a/fastapi_cachex/manager.py b/fastapi_cachex/manager.py index 7b935fc..3a86010 100644 --- a/fastapi_cachex/manager.py +++ b/fastapi_cachex/manager.py @@ -55,9 +55,9 @@ def _cache_key(self, key: str) -> str: @staticmethod def _encode(value: Any) -> CacheEntry: - json_content = json.dumps(value) - fingerprint = hashlib.sha256(json_content.encode()).hexdigest() - return CacheEntry(fingerprint=fingerprint, content=json_content.encode("utf-8")) + content = json.dumps(value).encode("utf-8") + fingerprint = hashlib.sha256(content).hexdigest() + return CacheEntry(fingerprint=fingerprint, content=content) async def get(self, key: str, default: Any = None) -> Any: """Retrieve and JSON-decode a cached value.