Mailing List Archive

Purge cache for mobile users
Hi,

Hope this is the right channel for solving the issue. Varnish has been
implemented a year ago, excellent response, working fine. But after
installation of Mobilefrontend several months later the issues were
detected. (mediawiki 1.38.2, varnish 7.1)
Purges after the page updates run and purge desktop entries automatically
as well, but when the same page is accessed from the mobile device, the old
page version before the update is shown, the mobile entry has not been
purged. Mobilefrontend is installed and configured as advised in
mw:Extension:MobileFrontend/Configuring_browser_auto-detection option 2,
same domain.
The only difference between requests for desktop/mobile version is in the
header x-subdomain: no for mobile version (shows during the debug in
varnishlog). But even curl sending this header for purge request did not
work.

Configuration:
Mediawiki:

wfLoadExtension( 'MobileFrontend' );
$wgMFAutodetectMobileView = true;
$wgMinervaEnableSiteNotice = true;
$wgMFDefaultSkinClass = 'SkinMinerva';
...
$wgInternalServer = "http://127.0.0.1:8080";
$wgUseCdn = true;
$wgCdnServers = array();
$wgCdnServers[] = "127.0.0.1:8080";

Varnish:
According https://www.mediawiki.org/wiki/Manual:Varnish_caching, it had to
be customized, the page is little out-of-date and according to:
https://www.mediawiki.org/wiki/Extension:MobileFrontend/Configuration a
https://www.mediawiki.org/wiki/Extension:MobileFrontend/Configuring_browser_auto-detection
.
In sub vcl_recv {
....
if (req.method == "PURGE") {
if ((req.http.X-Forwarded-For == "ip address") ||
(req.http.X-Forwarded-For == "ip address") ||
(req.http.X-Forwarded-For == "ip address")) {
set req.http.host = "host";
return (hash);
} else {
return (synth(405, "Not allowed"));
}
}
...
unset req.http.x-subdomain; # Requester shouldn't be allowed to
supply arbitrary X-Subdomain header
if (req.http.User-Agent ~
"(?i)^(lg-|sie-|nec-|lge-|sgh-|pg-)|(mobi|240x240|240x320|320x320|alcatel|android|audio
vox|bada|benq|blackberry|cdm-|compal-|docomo|ericsson|hiptop|htc[-_]|huawei|ipod|kddi-|kindle|meego|midp|mitsu|mmp\/|mot-
|motor|ngm_|nintendo|opera.m|palm|panasonic|philips|phone|playstation|portalmmm|sagem-|samsung|sanyo|sec-|sendo|sharp|sof
tbank|symbian|teleca|up.browser|webos)") {
set req.http.x-subdomain = "no";
}
...
return (hash);
...

sub vcl_hash {
# Cache the mobile version of pages separately.
#
# NOTE: x-subdomain header should only have one value (if it
exists),
# therefore vcl_recv() should remove user-supplied X-Subdomain
header.
hash_data(req.http.x-subdomain);
}
...
import purge;

sub my_purge {
set req.http.purged = purge.soft(0s,30s);
if (req.http.purged == "0") {
return (synth(404));
}
else {
return (synth(200));
}
}

After the purge if someone does not request the page and it would not be
loaded into cache, after 30 seconds the page should be loaded automatically.

The consequence of the issue is that mobile users do not see up-to-date
versions of the pages, the only workaround is restart varnish.

Thanks for advice pointing to the solution.

Pavel Spacek