Reset memoize cache if unable to unpickle

This is usually due to the cache being stored with Python 3 and then
attempted to being loaded in Python 2 which raises a ValueError.

Closes #138.
This commit is contained in:
Kim Silkebækken 2013-01-27 17:40:02 +01:00
parent 38195f490e
commit d6da2c8d98

View File

@ -29,8 +29,8 @@ class memoize(object):
try:
with open(self.persistent_file, 'rb') as fileobj:
self._cache = pickle.load(fileobj)
except (IOError, EOFError):
pass
except (IOError, EOFError, ValueError):
self._cache = {}
cached = self._cache.get(key, None)
if cached is None or time.time() - cached['time'] > self.timeout:
cached = self._cache[key] = {