MediaWiki HTTP cache headers
Appearance
(Redirected from MediaWiki caching)
This page may be outdated or contain incorrect details. Please update it if you can.
This article is about MediaWiki-based caching. For CDN caching, see CDN#Caching.
Varnish and Apache Traffic Server cache Wikipedia content.
MediaWiki caching headers are sent mainly in OutputPage.php, function sendCacheControl()
. The headers sent depend mainly on the action and if a cookie is sent by the browser.
- cache-control
-
- s-maxage: Tells intermediate caches how long they should consider the content to be valid without ever checking back. This needs to be hidden from caches we can't purge, otherwise users won't see changes.
- max-age: For how long browsers should deem the content as up-to-date. We allow clients to keep the page (the "private" header allows this) but tell them to send a conditional
if-modified-since
request. For this theLast-modified
header is needed; We set the header value to the last modification time or - if we don't have it - to the current time minus one hour. Images and stylesheets (including the generated ones that represent the user's preference selections) havemax-age > 0
to avoid reloading those on each request. This is the reason why users have to refresh their cache after changing their preferences. - private: Allows browsers to cache content.
- Example:
Cache-Control: private, s-maxage=0, max-age=0, must-revalidate
- last-modified
- This is required for client-side caching, as without it browsers don't know what to base their
if-modified-since
requests on. If the page hasn't changed the cache will only respond with a 304 (unchanged) status code, and only the response code and headers are transferred.
- vary
- Tells downstream proxy caches to cache the content depending on some values — if those values are different, serve another page for the same url.
- Accept-Encoding Clients that don't support gzip transfer-encoding don't get compressed pages.
- Cookie Make sure logged-in users (which send a cookie) get pages with their user name and preferences.
- Example:
vary: Accept-Encoding, Cookie