diff options
author | Starfall <us@starfall.systems> | 2023-01-09 20:24:50 -0600 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2023-01-09 20:24:50 -0600 |
commit | 7ab7f137af94d6f64f33dbf9dbec05e772b0d5c7 (patch) | |
tree | f1b850f28cb004249f9be9107a028f9e7e4ebedb /fscache.py | |
parent | 6636a4a0a59dc73cdd4a0e123363794574415df5 (diff) |
Diffstat (limited to 'fscache.py')
-rw-r--r-- | fscache.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/fscache.py b/fscache.py index e549e92..8e57a6e 100644 --- a/fscache.py +++ b/fscache.py @@ -2,6 +2,9 @@ import os import time from pathlib import Path +def key_rewrite(key): + return key.replace('/', '-') + class CacheMiss(Exception): pass @@ -14,7 +17,9 @@ class Cache: self.cache_dir = Path(os.environ['HOME'])/'.cache'/name self.cache_dir.mkdir(exist_ok=True) + def write(self, key, value, ttl=None): + key = key_rewrite(key) loc = self.cache_dir/key loc.write_text(value, errors='ignore') @@ -24,6 +29,7 @@ class Cache: os.utime(loc, (stat.st_atime, stat.st_mtime + ttl)) def read(self, key): + key = key_rewrite(key) loc = self.cache_dir/key if not loc.exists(): |