Request cache should not update context

The request context is kind of important. It has info like the
request cache and auth info for the request.

The request cache should not be modifying the request context. The
code here makes it look like the request cache needs to update the
thread's request context but it actually never does change it since
even if it creates a new RequestContext the new instance becomes
the new thread request context.

Change-Id: Ib824648fe7cb6b3614e03f7d2570fbbfc0c3a88d
This commit is contained in:
Brant Knudson 2016-09-22 17:29:40 -05:00 committed by Boris Bobrov
parent dc9a1d5f70
commit 6ed37d2410
1 changed files with 3 additions and 7 deletions

View File

@ -39,14 +39,12 @@ class _ResponseCacheProxy(proxy.ProxyBackend):
def _get_request_key(self, key):
return self.__key_pfx % key
def _set_local_cache(self, key, value, ctx=None):
def _set_local_cache(self, key, value):
# Set a serialized version of the returned value in local cache for
# subsequent calls to the memoized method.
if not ctx:
ctx = self._get_request_context()
ctx = self._get_request_context()
serialize = {'payload': value.payload, 'metadata': value.metadata}
setattr(ctx, self._get_request_key(key), msgpackutils.dumps(serialize))
ctx.update_store()
def _get_local_cache(self, key):
# Return the version from our local request cache if it exists.
@ -65,7 +63,6 @@ class _ResponseCacheProxy(proxy.ProxyBackend):
ctx = self._get_request_context()
try:
delattr(ctx, self._get_request_key(key))
ctx.update_store()
except AttributeError: # nosec
# NOTE(morganfainberg): We will simply pass here, this value has
# not been cached locally in the request.
@ -99,9 +96,8 @@ class _ResponseCacheProxy(proxy.ProxyBackend):
return [values[k] for k in keys]
def set_multi(self, mapping):
ctx = self._get_request_context()
for k, v in mapping.items():
self._set_local_cache(k, v, ctx)
self._set_local_cache(k, v)
self.proxied.set_multi(mapping)
def delete_multi(self, keys):