for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
import os
import pickle
class Cache(object):
PATH = os.path.join('.cache', 'coverage.space')
def __init__(self, data=None):
try:
assert isinstance(data, dict)
except AssertionError:
self._data = {}
else:
self._data = data
@classmethod
def load(cls):
with open(cls.PATH, 'r') as fin:
data = pickle.load(fin)
except IOError:
return cls()
return cls(data)
def _store(self):
with open(self.PATH, 'w') as fout:
pickle.dump(self._data, fout)
def match(self, key, value):
cached = self._data.get(key)
self._data[key] = value
self._store()
return value == cached