WPCloud Deploy Documentation

Page Cache

Introduction

WordPress is a PHP application which means that every request for a page or resource requires a compilation step.  This dramatically increases the response time and adds substantial load to the server.  But, most pages and resources are static or do not often change.  This means that once the page or resource has been compiled, it can be stored so that the next request does not require the compilation step.

The feature that implements this idea is called a “Page Cache”.  Almost every WordPress host you’ve ever used provides some sort of ability to enable a page caching service.  Most use an NGINIX based page cache, a REDIS page cache, a VARNISH based page cache or a proprietary page cache.  But they all aim to do the same thing – store a pre-compiled WordPress page or object so that it can be served much faster.

The WPCloudDeploy Plugin uses either an NGINX based page cache or the native OpenLiteSpeed server page cache, depending on which webserver is in use.

NGINX Web Servers

The WPCloudDeploy Plugin uses the NGINX web server to manage a WordPress page cache.  In order to do this, it requires a WordPress plugin called CACHE ENABLER (published by KEY CDN).  When you enable the page cache in the WPCloudDeploy admin area, the plugin is automatically installed and enabled.

The plugin automatically generates and places pages into the page cache folder which NGINX first checks before serving up a page.

The following pages are automatically excluded from the cache:

  • Any page with data from forms
  • URLS with query data strings
  • Pages served when the user is logged in.

The Cache-Enabler plugin for NGINX stores cache files in the following location:

/var/www/myblog.com/html/wp-content/cache/cache-enabler/

Why NGINX?

There are many ways to handle a page cache.  A couple we have already mentioned: REDIS & VARNISH.  We decided not to use any of those simply because we’re already using NGINX and NGINX can already make very efficient use a cache – if one is set up.  This greatly reduces the complexity of the tech stack as well as reduces the memory in use and removes another potential point of failure where things can go wrong.


OpenLiteSpeed Web Servers

When using an OpenLiteSpeed web server, we use the built-in OpenLiteSpeed page cache along with the OpenLiteSpeed WordPress plugin.


Caching And WordPress Crons

WordPress fires off its scheduled activities (‘cron’) only when a site has traffic.  In other words, when WordPress is called to load a page or post, it also checks to see what other activities are in the scheduler that also needs to be completed.  If WordPress isn’t called to load a page, scheduled activities are not run.

When a page is cached, WordPress is never called.  Which means that some scheduled activities might be delayed or not get run at all.

So, if you’re using a page cache and you expect most of your site requests to be served from the cache, we recommend that you turn on the LINUX based cron process – you can do this from the CRON tab on your site.


Turning On The Page Cache

To turn on the page cache:

  1. Go to WPCloudDeploy->Applications
  2. Click on the site where you need to turn on the page cache
  3. Click on the Cache tab
  4. Scroll down to the PAGE CACHE section
  5. Click on the toggle switch

If you are using an NGINX web server you can verify that the cache is turned on by viewing the source code for a page in a browser.  At the very bottom of the page code you should see something that looks like this:

<!-- Cache Enabler by KeyCDN @ 07.02.2021 00:13:37 (https html) -->

If you do  not see this then either the page is not cacheable or we were unable to add a required entry to your wp-config.php file.   Open your wp-config.php and verify that this entry exists:

define( 'WP_CACHE', 'true' );

It might be wrapped in a conditional such as:

if ( ! defined( 'WP_CACHE' ) ) {
define( 'WP_CACHE', 'true' );
}

If you do not see it then you should add it!

Clearing The Page Cache

There are times when you need to clear the cache so that it can be rebuilt. To do this:

  1. Go to WPCloudDeploy->Applications
  2. Click on the site where you need to turn on the page cache
  3. Click on the Cache tab
  4. Scroll down to the PAGE CACHE section
  5. Click on the Clear button

Add Exceptions To The Page Cache

Nginx Web Server

Exceptions need to be added from your sites’ WordPress dashboard, not the WPCloudDeploy dashboard.

  1. Go to your WordPress sites’ Settings->Cache Enabler screen in wp-admin
  2. Fill in the items as necessary
  3. Click the Save Changes button.

OpenLiteSpeed Web Server

  1. Go to your WordPress sites’ LiteSpeedCache -> Cache screen in wp-admin
  2. Click on the EXCLUDES tab
  3. Fill in the items as necessary
  4. Click the Save Changes button.

Availability

The OpenLiteSpeed Web Server cache options are only available in WPCD V 5.0.0 or later.


Share: