補強 cache best-effort 診斷
All checks were successful
CD Pipeline / deploy (push) Successful in 56s

This commit is contained in:
OoO
2026-05-13 11:04:34 +08:00
parent 8a36856171
commit 5b52af9e2f
2 changed files with 9 additions and 2 deletions

View File

@@ -8,10 +8,14 @@ module-level cache 收斂到這裡,避免各 route 各自持有一份 dict。
"""
import os
import logging
import time
from pathlib import Path
logger = logging.getLogger(__name__)
class FingerprintCache:
"""TTL + fingerprint 的小型 in-memory cache。"""
@@ -30,13 +34,14 @@ class FingerprintCache:
if self._fp_fn() != entry['fp']:
return None
except Exception:
pass
logger.debug("cache fingerprint check failed for %s", self.name, exc_info=True)
return entry['data']
def set(self, key, data):
try:
fp = self._fp_fn()
except Exception:
logger.debug("cache fingerprint write failed for %s", self.name, exc_info=True)
fp = None
self._store[key] = {'data': data, 'ts': time.time(), 'fp': fp}
@@ -137,4 +142,4 @@ def clear_dashboard_cache():
except FileNotFoundError:
pass
except OSError:
pass
logger.debug("dashboard shared cache cleanup failed", exc_info=True)