diff options
author | Mark Haines <mark.haines@matrix.org> | 2015-05-05 16:24:04 +0100 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2015-05-05 16:24:04 +0100 |
commit | 63075118a528d1abf0b146a961ec5c571bf058b2 (patch) | |
tree | dcc4d0f60353427f83389822622578c78342fd5e /synapse/storage | |
parent | Invalidate the room_member cache if the current state events updates (diff) | |
download | synapse-63075118a528d1abf0b146a961ec5c571bf058b2.tar.xz |
Add debug flag in synapse/storage/_base.py for debugging the cache logic by comparing what is in the cache with what was in the database on every access
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/_base.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py index 7f5477dee5..840a4994bb 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py @@ -33,6 +33,7 @@ import sys import time import threading +DEBUG_CACHES = False logger = logging.getLogger(__name__) @@ -146,7 +147,17 @@ def cached(max_entries=1000, num_args=1, lru=False): @defer.inlineCallbacks def wrapped(self, *keyargs): try: - defer.returnValue(cache.get(*keyargs)) + cached_result = cache.get(*keyargs) + if DEBUG_CACHES: + actual_result = yield orig(self, *keyargs) + if actual_result != cached_result: + logger.error( + "Stale cache entry %s%r: cached: %r, actual %r", + orig.__name__, keyargs, + cached_result, actual_result, + ) + raise ValueError("Stale cache entry") + defer.returnValue(cached_result) except KeyError: sequence = cache.sequence |