Skip to content

Back

Controlling caches within WordPress Hosting

Applies to:
WordPress Hosting

Introduction

Caching allows resource intensive tasks such as generating a page or running complex queries to be stored temporarily so they are not done on every page visit. This makes pages run faster and allow more visitors to access a page at once. The WordPress Hosting has multiple levels of caching including Full Page, Object and Database caching.


Clearing Caches

Clearing All Caches

Our built in caching, also automatically clear themselves in certain situations (see notes below) and really clearing the cache is something you would only manually do for testing, or after installing a new theme. Publishing a post for example would automatically flush the cache.

To clear all caches manually from within WordPress

  1. Within the WordPress Admin area, select Hosting Tools from the Admin menu bar
  2. Clear All Caches

This clears both the Object and Full Page Cache.

To clear all pages from within 34SP.com Client Control Panel

  1. Navigate to your domain
  2. Click Clear Cache button

Again this clears both the Object and Full Page Cache

To clear all caches from CLI

  1. SSH into container
  2. Navigate to site httpdocs
  3. Type wp hosting cache clear

Once again this clears both the object and the full page cache

Clear Page Cache

Sometimes you might just want to clear the Nginx Page Cache to do so within WordPress admin area:

Clear Object Cache

To clear just the object cache, you can use the built in WP-CLI command so via CLI

  1. SSH into Container
  2. Navigate to httpdocs
  3. Type wp cache flush

Enabling/Disabling Full page cache

By default the Full Page cache is on and enabled for all sites, we recommend keeping full page caching enabled and selectively disabling it for specific pages.

Disabling Full page caching on specific pages (Whitelisting)

To disable caching a specific page, you must add it to the whitelist.

Via the WordPress Admin:

  1. Navigate to Tools → Hosting Tools
  2. Place the full URL in the “Whitelist pages from cache” textarea

You can use a Full url for example:

http://example.com/myshop/basket

Or wild card

http://example.com/myshop/*

Removing a URL from the list, removes it from the whitelist and the content will be cached.

Programmatically (Advanced)

We offer two options for developers wanting to whitelist one is a filter to the whitelist array, the second is sending a HTTP Header from any page.

Adding Filter

Filter entries are added at time of the URL being checked and do not show in the admin area list.

            
add_filter('TFSP_CACHE_WHITELIST', 'example_filter');

function example_filter($whitelist)
{
  return $whitelist[] = 'https://example.com/shop';
}
            
          

Adding HTTP Header

Setting a HTTP Header, will tell Nginx to not cache the result, the header is then stripped before passing to the client.

            
header( 'X-Tfsp-Override: BYPASS' );
            
          

Totally Disabling Full Page Caching

Switching off the Full Page caching is not advised but can be done via WordPress Admin area

  1. Navigate to Tools → Hosting Tools
  2. Click Disable Caching

To enable repeat the process.


Enabling/Disabling Object Cache

Disabling/Enabling the object cache, does not stop WordPress default behaviours, it however stops the object cache being stored in Redis, and return to the default behaviour of storing objects in the wp_options table.

Disabling the object cache storage in Redis can be done by editing your my-config.php with the following:

define('34SP_OBJECT_CACHE_OFF', true);         

We do strongly recommend only turning off the object cache for debugging as it provides significant speed improvements.


Notes

Identifying if a page is being full page cached (advanced)

Pages that are being retrieved from the cache will respond with the header

            
x-fastcgi-cache: HIT
            
          

The other options being Miss & Bypass

  1. Hit – Retrieved from the cache
  2. Miss – An attempt was made to retrieve but it wasn’t there
  3. ByPass – The system didn’t look in the cache.

Miss normally means on subsequent page visits the result should be cached. Bypass normally means a cookie has been set, or that the page has been marked in the whitelist.

Automated Clearing of caches

By default Publishing a post/page or other content type, modifying categories/tags, adding/editing Menus/Widgets or using the customiser will cause the Full page cache to be emptied.

To prevent lot’s of requests being made, the Automated cache flush, sets a scheduled task to flush the cache. Meaning it can take up to 5 minutes for the cache flush to occur.

Browser caching

Many Performance guides will reference “Leverage Browser Caching” this means that static assets like Images, or fonts that won’t change are stored in the browser for a fixed period in the browsers own cache. The browser will not ask the server for the files unless a “hard refresh” is done by default we set a 30 day expiry header on: Images, Font’s and CSS/JS files.

However we do not set an expiry if the “asset” is loaded with a query string for example example.css?version=4.9.9 by default WordPress adds such strings to CSS and Javascript. If you wish to remove them, then we recommend a plugin like https://wordpress.org/plugins/wp-remove-query-strings-from-static-resources/

Was this article helpful?
YesNo