diff options
author | Erik Johnston <erik@matrix.org> | 2019-08-12 15:39:14 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2019-08-13 16:20:38 +0100 |
commit | 17e1e807264ce13774d9b343c96406795ea24c27 (patch) | |
tree | ae21442fa71066b889a5cc2d83da95a699146590 /synapse/util/caches | |
parent | Don't load the media repo when configured to use an external media repo (#5754) (diff) | |
download | synapse-17e1e807264ce13774d9b343c96406795ea24c27.tar.xz |
Retry well-known lookup before expiry.
This gives a bit of a grace period where we can attempt to refetch a remote `well-known`, while still using the cached result if that fails. Hopefully this will make the well-known resolution a bit more torelant of failures, rather than it immediately treating failures as "no result" and caching that for an hour.
Diffstat (limited to 'synapse/util/caches')
-rw-r--r-- | synapse/util/caches/ttlcache.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/synapse/util/caches/ttlcache.py b/synapse/util/caches/ttlcache.py index 2af8ca43b1..99646c7cf0 100644 --- a/synapse/util/caches/ttlcache.py +++ b/synapse/util/caches/ttlcache.py @@ -55,7 +55,7 @@ class TTLCache(object): if e != SENTINEL: self._expiry_list.remove(e) - entry = _CacheEntry(expiry_time=expiry, key=key, value=value) + entry = _CacheEntry(expiry_time=expiry, ttl=ttl, key=key, value=value) self._data[key] = entry self._expiry_list.add(entry) @@ -87,7 +87,8 @@ class TTLCache(object): key: key to look up Returns: - Tuple[Any, float]: the value from the cache, and the expiry time + Tuple[Any, float, float]: the value from the cache, the expiry time + and the TTL Raises: KeyError if the entry is not found @@ -99,7 +100,7 @@ class TTLCache(object): self._metrics.inc_misses() raise self._metrics.inc_hits() - return e.value, e.expiry_time + return e.value, e.expiry_time, e.ttl def pop(self, key, default=SENTINEL): """Remove a value from the cache @@ -158,5 +159,6 @@ class _CacheEntry(object): # expiry_time is the first attribute, so that entries are sorted by expiry. expiry_time = attr.ib() + ttl = attr.ib() key = attr.ib() value = attr.ib() |