Propogate stale cache errors to calling functions

This commit is contained in:
Erik Johnston 2015-08-07 19:17:58 +01:00
parent 63b1eaf32c
commit 62126c996c

View File

@ -183,8 +183,8 @@ class CacheDescriptor(object):
try: try:
cached_result_d = cache.get(*keyargs) cached_result_d = cache.get(*keyargs)
observed = cached_result_d.observe()
if DEBUG_CACHES: if DEBUG_CACHES:
@defer.inlineCallbacks @defer.inlineCallbacks
def check_result(cached_result): def check_result(cached_result):
actual_result = yield self.function_to_call(obj, *args, **kwargs) actual_result = yield self.function_to_call(obj, *args, **kwargs)
@ -195,9 +195,10 @@ class CacheDescriptor(object):
cached_result, actual_result, cached_result, actual_result,
) )
raise ValueError("Stale cache entry") raise ValueError("Stale cache entry")
cached_result_d.observe().addCallback(check_result) defer.returnValue(cached_result)
observed.addCallback(check_result)
return cached_result_d.observe() return observed
except KeyError: except KeyError:
# Get the sequence number of the cache before reading from the # Get the sequence number of the cache before reading from the
# database so that we can tell if the cache is invalidated # database so that we can tell if the cache is invalidated