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

Commit

Permalink
Optimise CacheDescriptor (#8594)
Browse files Browse the repository at this point in the history
don't bother constricting a CacheContext unless we need one.
  • Loading branch information
richvdh authored Oct 21, 2020
1 parent 15d5553 commit b28aaeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit b28aaeb

Please sign in to comment.