summary refs log tree commit diff
path: root/synapse/http/federation
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-08-06 16:27:46 +0100
committerErik Johnston <erik@matrix.org>2019-08-06 17:01:23 +0100
commitaf9f1c07646031bf267aa20f2629d5b96c6603b6 (patch)
tree15dccf6f8ce7c589bda29b760d72c56f3de456c3 /synapse/http/federation
parentMerge pull request #5825 from matrix-org/erikj/fix_empty_limited_sync (diff)
downloadsynapse-af9f1c07646031bf267aa20f2629d5b96c6603b6.tar.xz
Add a lower bound for TTL on well known results.
It costs both us and the remote server for us to fetch the well known
for every single request we send, so we add a minimum cache period. This
is set to 5m so that we still honour the basic premise of "refetch
frequently".
Diffstat (limited to 'synapse/http/federation')
-rw-r--r--synapse/http/federation/matrix_federation_agent.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/synapse/http/federation/matrix_federation_agent.py b/synapse/http/federation/matrix_federation_agent.py
index a0d5139839..79e488c942 100644
--- a/synapse/http/federation/matrix_federation_agent.py
+++ b/synapse/http/federation/matrix_federation_agent.py
@@ -47,6 +47,9 @@ WELL_KNOWN_INVALID_CACHE_PERIOD = 1 * 3600
 # cap for .well-known cache period
 WELL_KNOWN_MAX_CACHE_PERIOD = 48 * 3600
 
+# lower bound for .well-known cache period
+WELL_KNOWN_MIN_CACHE_PERIOD = 5 * 60
+
 logger = logging.getLogger(__name__)
 well_known_cache = TTLCache("well-known")
 
@@ -356,6 +359,7 @@ class MatrixFederationAgent(object):
             cache_period += random.uniform(0, WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER)
         else:
             cache_period = min(cache_period, WELL_KNOWN_MAX_CACHE_PERIOD)
+            cache_period = max(cache_period, WELL_KNOWN_MIN_CACHE_PERIOD)
 
         return (result, cache_period)