Skip to content
Snippets Groups Projects
Unverified Commit b28aaeb3 authored by Richard van der Hoff's avatar Richard van der Hoff Committed by GitHub
Browse files

Optimise CacheDescriptor (#8594)

don't bother constricting a CacheContext unless we need one.
parent 15d5553d
No related branches found
No related tags found
Loading
Minor optimisations in caching code.
......@@ -201,14 +201,16 @@ class CacheDescriptor(_CacheDescriptorBase):
cache_key = get_cache_key(args, kwargs)
# Add our own `cache_context` to argument list if the wrapped function
# has asked for one
if self.add_cache_context:
kwargs["cache_context"] = _CacheContext.get_instance(cache, cache_key)
try:
ret = cache.get(cache_key, callback=invalidate_callback)
except KeyError:
# Add our own `cache_context` to argument list if the wrapped function
# has asked for one
if self.add_cache_context:
kwargs["cache_context"] = _CacheContext.get_instance(
cache, cache_key
)
ret = defer.maybeDeferred(preserve_fn(self.orig), obj, *args, **kwargs)
ret = cache.set(cache_key, ret, callback=invalidate_callback)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment