Skip to content

Commit e8cb1d2

Browse files
committed
Explain better the reasoning for specific Cache-Control headers
1 parent 70568af commit e8cb1d2

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

synapse/rest/client/auth_metadata.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ def __init__(self, hs: "HomeServer"):
5050

5151
async def on_GET(self, request: SynapseRequest) -> tuple[int, JsonDict]:
5252
# This endpoint is unauthenticated and the response only depends on
53-
# the upstream OIDC provider metadata, so it can be cached.
53+
# the metadata we get from Matrix Authentication Service. Internally,
54+
# MasDelegatedAuth/MSC3861DelegatedAuth.issuer() are already caching the
55+
# response in memory anyway. Ideally we would follow any Cache-Control directive
56+
# given by MAS, but this is fine for now.
57+
#
58+
# - `public` means it can be cached both in the browser and in caching proxies
59+
# - `max-age` controls how long we cache on the browser side. 1h is sane enough
60+
# - `s-maxage` controls how long we cache on the proxy side. Since caching
61+
# proxies usually have a way to purge caches, it is fine to cache there for
62+
# longer (24h), and issue cache invalidations in case we need it
5463
request.setHeader(b"Cache-Control", b"public, max-age=600, s-maxage=3600")
5564

5665
if self._config.mas.enabled:
@@ -99,7 +108,16 @@ def __init__(self, hs: "HomeServer"):
99108

100109
async def on_GET(self, request: SynapseRequest) -> tuple[int, JsonDict]:
101110
# This endpoint is unauthenticated and the response only depends on
102-
# the upstream OIDC provider metadata, so it can be cached.
111+
# the metadata we get from Matrix Authentication Service. Internally,
112+
# MasDelegatedAuth/MSC3861DelegatedAuth.issuer() are already caching the
113+
# response in memory anyway. Ideally we would follow any Cache-Control directive
114+
# given by MAS, but this is fine for now.
115+
#
116+
# - `public` means it can be cached both in the browser and in caching proxies
117+
# - `max-age` controls how long we cache on the browser side. 1h is sane enough
118+
# - `s-maxage` controls how long we cache on the proxy side. Since caching
119+
# proxies usually have a way to purge caches, it is fine to cache there for
120+
# longer (24h), and issue cache invalidations in case we need it
103121
request.setHeader(b"Cache-Control", b"public, max-age=3600, s-maxage=86400")
104122

105123
if self._config.mas.enabled:

synapse/rest/client/versions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ async def on_GET(self, request: SynapseRequest) -> tuple[int, JsonDict]:
8484
else:
8585
# Allow caching of unauthenticated responses, as they only depend
8686
# on server configuration which rarely changes.
87+
#
88+
# - `public` means it can be cached both in the browser and in caching proxies
89+
# - `max-age` controls how long we cache on the browser side. 10m is sane enough
90+
# - `s-maxage` controls how long we cache on the proxy side. Since caching
91+
# proxies usually have a way to purge caches, it is fine to cache there for
92+
# longer (1h), and issue cache invalidations in case we need it
8793
request.setHeader(b"Cache-Control", b"public, max-age=600, s-maxage=3600")
8894

8995
# Tell caches to vary on the Authorization header, so that

0 commit comments

Comments
 (0)