ckharche commited on
Commit
58413ce
Β·
verified Β·
1 Parent(s): 2b77f9a

Update trade_analysis/cache.py

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