Today we are introducing WordPress page caching. While PHP 7 brought massive improvements in performance, not caching your site can bring it to a crawl when your visitor count goes up. Sooner or later every WordPress site owner comes into contact with cache plugins. They do a good job but they still require PHP to execute on every page load. With WP Next we serve the cache directly from the web server and you don’t have to install any cache plugins. It’s fast directly out of the box.
What is WordPress page caching?
When a request comes into a WordPress site a number of things happen
- PHP must be started to run the WordPress code base
- MySQL gets called to get the content for the page
- WordPress plugins execute
With page caching enabled the web server saves the result of all that work and it can be used for the next request. Since we don’t need to start PHP and communicate with the database the speedup is massive, letting us serve what would be a dynamic request like a static file on the server.
WP Next cache settings
When you create a new site we automatically enable caching for you. For old sites you can enable it in the WP Next panel under the settings tab for that site.
The cache can also be cleared directly from the control panel.
How to tell if the cache is working?
When caching is enabled on your site we append an additional HTTP header (X-Cache) to all responses (except for static resources) to communicate the status of the cache. HIT, MISS and BYPASS are the most common values you will see.
HIT and MISS are the easiest to understand. When a page was served directly from the cache you will receive a HIT. If the page wasn’t in the cache then the X-Cache header will be set to MISS (but the next request will result in a HIT). If you get a BYPASS value then we did not attempt to use the cache. There are certain instances where we bypass the cache system because it would not be safe to cache. A good example of this would be the WooCommerce cart page.
Automatic clearing of cache
The WP Next worker plugin, that we install automatically, takes care of clearing the cache when you update the site contents. The cache also has a lifetime of 60 minutes. When this time is reached we clear the cache for that page and request a fresh version from the backend.