diff --git a/oxrlib/cache.py b/oxrlib/cache.py index 03511d49d7f5de148ae2e9611226160bf291a97c..6792c3cf0649acfeccc08d83df6b157d5c3e5467 100644 --- a/oxrlib/cache.py +++ b/oxrlib/cache.py @@ -1,4 +1,5 @@ import functools +import json from . import errors @@ -77,3 +78,10 @@ class CacheWriter(CacheBase): def open(self, path): return self.CacheFile(path, 'w') + + def write_json(self, cache_file, thing): + json.dump(thing, cache_file, indent=2) + + def save_rate(self, rate): + with self.historical(rate.timestamp.date(), rate.base) as cache_file: + self.write_json(cache_file, rate.serialize())