Fix serialization of blobs to/from the cache

Also makes sure the test checks that serialization
This commit is contained in:
Joseph Schorr 2018-03-02 14:22:55 -05:00
parent 0bc1a06f4c
commit 24b77bbc10
3 changed files with 12 additions and 6 deletions

4
data/cache/impl.py vendored
View file

@ -48,7 +48,7 @@ class InMemoryDataModelCache(DataModelCache):
result = self.cache.get(cache_key.key, default_value=not_found)
if result != not_found:
logger.debug('Found result in cache for key %s: %s', cache_key.key, result)
return result
return json.loads(result)
logger.debug('Found no result in cache for key %s; calling loader', cache_key.key)
result = loader()
@ -57,7 +57,7 @@ class InMemoryDataModelCache(DataModelCache):
logger.debug('Caching loaded result for key %s with expiration %s: %s', cache_key.key,
result, cache_key.expiration)
expires = convert_to_timedelta(cache_key.expiration) + datetime.now()
self.cache.set(cache_key.key, result, expires=expires)
self.cache.set(cache_key.key, json.dumps(result), expires=expires)
logger.debug('Cached loaded result for key %s with expiration %s: %s', cache_key.key,
result, cache_key.expiration)
else: