Caching issues (WordPress)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

Caching is the most amazing thing since bread came sliced, if it wasn't for all the issues, errors and confusion that comes along with it - Enjoy!

Visitors see something different...

I have often experienced that when logged in (as admin), I see different things, compaired to visiting the same site without being logged in, through a Chrome guest session. This usually is due to caching: Logged-in users, especially admins, don't get cached stuff. Visitors do. So if there is something wrong with what guests see, it's probably that they see something that is cached.

Some ways to alluviate this (this is actually what this whole article is about):

  • Disable caching
  • Remove residiual cache files
  • Add cache-control headers?

Add cache-control headers

A fresh idea from ChatGPT to assure that fresh content is being served. Add this to your site's .htaccess file:

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/html "access plus 0 seconds"
</IfModule>

<IfModule mod_headers.c>
  Header set Cache-Control "no-cache, no-store, must-revalidate"
  Header set Pragma "no-cache"
  Header set Expires "0"
</IfModule>

Caches at different levels

  • WP Transients
  • Settings in wp-config.php
  • Drop-in caches
  • Object caches
  • MU-caches
  • Residual cache files, e.g., at wp-content/cache
  • Regular caching plugins
  • Server-sided caching
  • External caches. E.g.: CloudFlare, CDNs, Reddis, Varnish, other?

Purge residual cache files

Just disabling or even deleting a plugin, is not enough: The residual cache files are somehow still used. If you don't take care of this, your in for a lot of confusion

WP Rocket

When it's specifically about WP Rocket:

  • Enable WP Rocket → Clear cache & Purge OPcache
  • Delete directory wp-content/cache/wp-rocket.

See WP Rocket (WordPress-plugin)#Deïnstallatie for details.

General

In general: Delete contents of directory wp-content/cache.

Flush caches

Many issues can be solved by flushing a cache. Inversely, without doing so, it will often be difficult to properly diagnose any underlying issue.

Browser cache

I keep being amazed, how many issues in this world get solved if you and/or I just flush our browser's cache - And how easy it is to overlook this. E.g.:

  • Theme doesn't look ok after an update? → Flush the cache (Theme-storingen (WordPress))
  • Special symbols not displayed correctly after an update? → Flush the cache

How to flush, clear or empty your browser's cache:

  • Firefox: Ctrl-Shift-b or Ctrl-Shift-Delete
  • Google Chrome: Ctrl-h or Ctrl-Shift-Delete
  • Safari: Cmd-Alt-e

See Browsercache legen for details.

Transients

Flush all transients through wp transient delete --all. In my experience (2024.06), WooCommerce sites will go to maintenance mode to first recreate some transients that appearantly, are really needed.

Plugins

Flushing cache of caching plugins, differs from plugin to plugin. There is usually a difference between flushing a cache and disabling the plugin.

Case: May 2022

Error in May 2022, after cloning a site:

$ wp
Fatal error: Uncaught RuntimeException: Failed to locate and load object cache API. in /var/www/example.com/wp-content/object-cache.php:52
Stack trace:
#0 /var/www/example.com/wp-includes/load.php(694): require_once()
#1 /var/www/example.com/wp-settings.php(131): wp_start_object_cache()
#2 phar:///opt/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1271): require('...')
#3 phar:///opt/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1192): WP_CLI\Runner->load_wordpress()
#4 phar:///opt/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(23): WP_CLI\Runner->start()
#5 phar:///opt/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(77): WP_CLI\Bootstrap\LaunchRunner->process()
#6 phar:///opt/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(27): WP_CLI\bootstrap()
#7 phar:///opt/wp/php/boot-phar.php(11): include('...')
#8 /opt/wp(4): include('...')
#9 {main}
  thrown in /var/www/example.com/wp-content/object-cache.php on line 52

After disabling all kinds of caching-specific settings in wp-config.php, the error message changed:

wp cache
Fatal error: Uncaught RuntimeException: Failed to locate and load Object Cache Pro plugin. in /var/www/example.com/wp-content/mu-plugins/redis-cache-pro.php:38
Stack trace:
#0 /var/www/example.com/wp-settings.php(349): include_once()
#1 phar:///opt/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1271): require('...')
#2 phar:///opt/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1192): WP_CLI\Runner->load_wordpress()
#3 phar:///opt/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(23): WP_CLI\Runner->start()
#4 phar:///opt/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(77): WP_CLI\Bootstrap\LaunchRunner->process()
#5 phar:///opt/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(27): WP_CLI\bootstrap()
#6 phar:///opt/wp/php/boot-phar.php(11): include('...')
#7 /opt/wp(4): include('...')
#8 {main}
  thrown in /var/www/example.com/wp-content/mu-plugins/redis-cache-pro.php on line 38
Error: Er heeft zich een kritieke fout voorgedaan op deze site.Meer informatie over probleemoplossing in WordPress. Er heeft zich een kritieke fout voorgedaan op deze site.

Then disabled the MU plugins by renaming the folder. Then the problem disappeared.

Case: Sep. 2022

Almost the same error, also during cloning of a site (nl_nleur_en) that relied heavily on caching (WP Rocket, Redis, more?):

Error

Fatal error: Uncaught RuntimeException: Failed to locate and load object cache API in /var/www/example.com/wp-content/object-cache.php:56
Stack trace:
#0 /var/www/example.com/wp-includes/load.php(694): require_once()
#1 /var/www/example.com/wp-settings.php(131): wp_start_object_cache()
#2 phar:///opt/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1271): require('...')
#3 phar:///opt/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1192): WP_CLI\Runner->load_wordpress()
#4 phar:///opt/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(23): WP_CLI\Runner->start()
#5 phar:///opt/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(77): WP_CLI\Bootstrap\LaunchRunner->process()
#6 phar:///opt/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(27): WP_CLI\bootstrap()
#7 phar:///opt/wp/php/boot-phar.php(11): include('...')
#8 /opt/wp(4): include('...')
#9 {main}
  thrown in /var/www/example.com/wp-content/object-cache.php on line 56
Error: Er heeft zich een kritieke fout voorgedaan op deze site.Meer informatie over probleemoplossing in WordPress. Er heeft zich een kritieke fout voorgedaan op deze site.

What I think it says

  • The error is generated in file wp-content/object-cache.php on line 56
  • In lines 31-40, this script tries to load various caching-related classes. When they all fail, the exception is thrown.

Solution: Remove object-cache.php

  • When I remove file /wp-content/object-cache.php, the error disappears. I believe this file is a drop-in replacement for native WordPress caching. Am I supposed to replace it with some original file, or just leave it like this?
  • In the same directory, there is a file advanced-cache.php, that also seems related to Redis or whatever. It seems I can also remove that (=changed the name).

Case: 2024.06

  • The problem: Admins see 13 items in a certain menu, while visitors see an older version of this menu, with only 8 items

Other information

  • Caching- and caching-related plugins were all disabled: a3 Lazy Load, Asset CleanUp, Debloat and WP Rocket
  • Transients: There were three transients with names like GFCache_2c... and one from JetPack, that should have been gone a long time ago.
  • Recently, we had another similar issue: Guests saw different (wrong) prices
  • Directory wp-content/mu-plugins is empty

Non-empty directory wp-content/cache:

  • busting - Empty
  • critical-css
  • debloat
  • min
  • used-css
  • wp-rocket - Lots of directories & files. File index-https.html (1.2MB) seems to contain a complete copy of the home page. The aforementioned menu has only 8 items here!

Possible causes

  • Object cache?
  • Maybe caching has been disabled, and the cache as it was at that moment, has been kept in use → That's it! Stale WP Rocket cache files that were still used.

Actions

  • Update all plugins - No difference
  • Remove empty file wp-content/advanced-cache.php - No difference
  • Remove content wp-content/cache/ → Solution.

See also