diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2020-10-21 22:57:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-21 22:57:45 +0100 |
commit | b28aaeb3a567ce1bbfd41796362b8bb0813ed0e3 (patch) | |
tree | 78d11a2d59052d7e0a2626429783ca03e260f9c5 | |
parent | Merge pull request #8593 from matrix-org/rav/cache_hacking/3 (diff) | |
download | synapse-release-v1.21.3.tar.xz |
Optimise CacheDescriptor (#8594) github/release-v1.21.3 release-v1.21.3
don't bother constricting a CacheContext unless we need one.
-rw-r--r-- | changelog.d/8594.misc | 1 | ||||
-rw-r--r-- | synapse/util/caches/descriptors.py | 12 |
2 files changed, 8 insertions, 5 deletions
diff --git a/changelog.d/8594.misc b/changelog.d/8594.misc new file mode 100644 index 0000000000..d266ba19a4 --- /dev/null +++ b/changelog.d/8594.misc @@ -0,0 +1 @@ +Minor optimisations in caching code. diff --git a/synapse/util/caches/descriptors.py b/synapse/util/caches/descriptors.py index a4172345ef..5d7fffee66 100644 --- a/synapse/util/caches/descriptors.py +++ b/synapse/util/caches/descriptors.py @@ -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) |