mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-17 14:44:20 -05:00
Optimise CacheDescriptor (#8594)
don't bother constricting a CacheContext unless we need one.
This commit is contained in:
parent
15d5553d9e
commit
b28aaeb3a5
1
changelog.d/8594.misc
Normal file
1
changelog.d/8594.misc
Normal file
@ -0,0 +1 @@
|
||||
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user