But problems arise in a clustered environment with multiple web servers. The update works on the master server but the change is not reflected on slave servers. Here’s why:
- W3 Total Cache generates the media query string from the browsercache.timestamp configuration value which is stored in wp-content/w3tc-config/master.php.
- To optimize performance, W3 Total Cache stores a parsed copy of the master.php file in wp-content/cache/config/master.php.
- Typically we exclude wp-content/cache from replication to slave servers as the cache folders can be very deep and slow replication.
- When the media query string is updated the slaves do not know that they need to regenerate the cached version of master.php.
In fact this problem occurs with any config change to W3 Total Cache. The changes will not be seen on slave servers unless the wp-content/cache/config/master.php file is deleted. After deletion the next request will regenerate the file with the new settings.
In our sync script we use a line like this to clear the config if needed:
[ /wp-content/w3tc-config/master.php -nt \
wp-content/cache/config/master.php ] && \
No each time the sync script runs, if the W3 Total Cache config has changed then the cached copy will be deleted and regenerated on the next request.