Page MenuHomePhabricator

Varnish cache doesn't work on /w/rest.php/wikifunctions/v0/fetch/:zid
Closed, ResolvedPublic

Description

Requests such as:

... are always a cache-miss in Varnish, even when only a few seconds have passed since a previous request to the same URL, to the same data center, from the same client. This despite the MediaWiki backend declaring a public Cache-Control header.

Might be related:

Event Timeline

Looks like this is due to a typo that was reproduced in the FetchHandler, later copied to the FunctionCallHandler implementation. Note s-max-age instead of s-maxage.

includes/RESTAPI/FetchHandler.php
	public function applyCacheControl( ResponseInterface $response ) {
		if ( $response->getStatusCode() >= 200 && $response->getStatusCode() < 400 ) {
			$response->setHeader( 'Cache-Control', 'public,must-revalidate,s-max-age=' . 60 * 60 * 24 );
		}
	}
includes/RESTAPI/FunctionCallHandler.php
	public function applyCacheControl( ResponseInterface $response ) {
		if ( $response->getStatusCode() >= 200 && $response->getStatusCode() < 300 ) {
			$response->setHeader( 'Cache-Control', 'public,must-revalidate,s-max-age=' . 60 * 60 * 24 );
		}
	}

Requests such as:

Code for this was added in https://gerrit.wikimedia.org/r/1018807 (T274269).

Code was added in https://gerrit.wikimedia.org/r/1071260 (T272516).

Change #1172504 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/extensions/WikiLambda@master] RESTAPI: Enable Varnish cache by fixing typo in "s-maxage"

https://gerrit.wikimedia.org/r/1172504

Change #1172504 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] RESTAPI: Fix typo in "s-maxage" to enable Varnish caching

https://gerrit.wikimedia.org/r/1172504

Jdforrester-WMF changed the task status from Open to In Progress.Jul 25 2025, 2:25 PM
Jdforrester-WMF subscribed.

To verify fix after train deploy next week.