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

This commit is contained in:
Mark Haines 2015-05-05 16:24:04 +01:00
parent bfa4a7f8b0
commit 63075118a5
1 changed files with 12 additions and 1 deletions

View File

@ -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