Spaces:
Sleeping
Sleeping
File size: 709 Bytes
58413ce 57a6af0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import json, time, pathlib, hashlib
CACHE_DIR = pathlib.Path("/tmp/.cache"); CACHE_DIR.mkdir(exist_ok=True)
TTL = 60*60*24 # 24 h
def _key(name): return CACHE_DIR / f"{hashlib.md5(name.encode()).hexdigest()}.json"
def put(n, obj):
_key(n).write_text(
json.dumps(obj, ensure_ascii=False),
encoding='utf-8' # ← Add this
)
def get(n):
fp = _key(n)
if not fp.exists():
return None
try:
data = fp.read_text(encoding='utf-8') # ← Add this
return json.loads(data)
except Exception as e:
print(f"Cache error: {e}")
return None
def put(n,obj): _key(n).write_text(json.dumps(obj,ensure_ascii=False), encoding='utf-8') |