summary refs log tree commit diff
path: root/synapse/util/caches/expiringcache.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-03-10 10:30:38 +0000
committerErik Johnston <erik@matrix.org>2017-03-10 10:30:49 +0000
commit3545e17f43a42273c60f8607ab9e9d56ff1946cd (patch)
tree59ad73948640ca0811c2f26ac49e27f85cd6dcdd /synapse/util/caches/expiringcache.py
parentFix docstring (diff)
downloadsynapse-3545e17f43a42273c60f8607ab9e9d56ff1946cd.tar.xz
Add setdefault key to ExpiringCache
Diffstat (limited to 'synapse/util/caches/expiringcache.py')
-rw-r--r--synapse/util/caches/expiringcache.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/synapse/util/caches/expiringcache.py b/synapse/util/caches/expiringcache.py
index 2987c38a2d..cbdde34a57 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