From 3545e17f43a42273c60f8607ab9e9d56ff1946cd Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 10 Mar 2017 10:30:38 +0000 Subject: [PATCH] Add setdefault key to ExpiringCache --- synapse/util/caches/expiringcache.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/synapse/util/caches/expiringcache.py b/synapse/util/caches/expiringcache.py index 2987c38a2..cbdde34a5 100644 --- a/synapse/util/caches/expiringcache.py +++ b/synapse/util/caches/expiringcache.py @@ -100,6 +100,13 @@ class ExpiringCache(object): except KeyError: return default + def setdefault(self, key, value): + try: + return self[key] + except KeyError: + self[key] = value + return value + def _prune_cache(self): if not self._expiry_ms: # zero expiry time means don't expire. This should never get called