Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Optimise CacheDescriptor #8594

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8594.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Minor optimisations in caching code.
12 changes: 7 additions & 5 deletions synapse/util/caches/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,16 @@ def _wrapped(*args, **kwargs):

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)

Expand Down