diff options
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(): |