summary refs log tree commit diff
path: root/synapse/storage/_base.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-08-06 14:01:05 +0100
committerErik Johnston <erik@matrix.org>2015-08-06 14:01:05 +0100
commit433314cc34295ffefca349b9fc6914d81f2521e0 (patch)
tree80825a5fc78fadf024c186be4d0e40e8d912171b /synapse/storage/_base.py
parentMerge branch 'erikj/cached_keyword_args' into erikj/cache_deferreds (diff)
downloadsynapse-433314cc34295ffefca349b9fc6914d81f2521e0.tar.xz
Re-implement DEBUG_CACHES flag
Diffstat (limited to 'synapse/storage/_base.py')
-rw-r--r--synapse/storage/_base.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 7b2be6745e..8384299a13 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -178,8 +178,23 @@ class CacheDescriptor(object):
             arg_dict = inspect.getcallargs(self.orig, obj, *args, **kwargs)
             keyargs = [arg_dict[arg_nm] for arg_nm in self.arg_names]
             try:
-                cached_result = cache.get(*keyargs)
-                return cached_result.observe()
+                cached_result_d = cache.get(*keyargs)
+
+                if DEBUG_CACHES:
+
+                    @defer.inlineCallbacks
+                    def check_result(cached_result):
+                        actual_result = yield self.function_to_call(obj, *args, **kwargs)
+                        if actual_result != cached_result:
+                            logger.error(
+                                "Stale cache entry %s%r: cached: %r, actual %r",
+                                self.orig.__name__, keyargs,
+                                cached_result, actual_result,
+                            )
+                            raise ValueError("Stale cache entry")
+                    cached_result_d.observe().addCallback(check_result)
+
+                return cached_result_d.observe()
             except KeyError:
                 # Get the sequence number of the cache before reading from the
                 # database so that we can tell if the cache is invalidated