Files
kenaito-conf/kenaito-conf-python-client/kenaito_conf/cache.py
T
odboy 03a95abb4b refactor: 客户端目录统一添加 kenaito-conf- 前缀
- go-client → kenaito-conf-go-client
- python-client → kenaito-conf-python-client
- python-client-demo → kenaito-conf-python-client-demo
- nodejs-client → kenaito-conf-nodejs-client
- nodejs-client-demo → kenaito-conf-nodejs-client-demo
- 更新所有 README 和 package.json 中的路径引用
2026-02-26 21:13:49 +08:00

23 lines
634 B
Python

import json
import os
CACHE_FILE = "config-cache.json"
class Cache:
def __init__(self, cache_dir: str = "."):
self.cache_dir = cache_dir
def write(self, data: dict) -> None:
path = os.path.join(self.cache_dir, CACHE_FILE)
with open(path, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False)
def read(self) -> dict | None:
path = os.path.join(self.cache_dir, CACHE_FILE)
try:
with open(path, "r", encoding="utf-8") as f:
return json.load(f)
except (FileNotFoundError, json.JSONDecodeError):
return None