This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user