An example of a support request we receive from time to time is in relation to object caching. Such support topics usually come about after a user encounters the below recommendation within the AMP plugin:
While caching can be a complex topic this document will expand on the above plugin recommendation, while providing insights into how persistent object caching works, why you should take advantage of persistent object caching, and how you can implement this for your AMP site.
What is caching #
There are many different types of caching, including browser caching, page caching, content delivery network caching (CDN) and object caching, all of which can all be categorized as either client side caching or server side caching.
While we don’t expand on the different types of caching here you can find out more about how caching works in this Google Developers Guide. Note that most of the WordPress plugins that offer caching solutions provide client side caching.
Object caching #
Similar to webpage resource requests above, WordPress database queries can add to overall page load time, in particular if a page has many queries running at a time. Object caching is a type of server side caching that stores query results to the database, as opposed to webpage content. This ensures better database efficiency by reducing expensive database query executions, resulting in faster loading times.
WordPress provides an object cache feature packaged into each WordPress install, in the form of wp_object_cache. On it’s own this cache can be used to store objects during a single request. If the same MySQL query is required more than once on the same request this saves repeated query calculations, and trips to the database. This is known as a non-persistent caching method – as it doesn’t persist query results across page loads. If you’re looking to use the same caching objects and really take advantage of the performance boosts across multiple page loads that’s where a persistent object caching can really help.
Persistent Object Caching #
Persistent Object Caching is similar to object caching above, with the primary difference being that cached objects are saved across multiple requests: they are persistent across page loads.
In order to achieve and enhance the power of the WordPress object cache, server side storage backends like Redis or Memcached can be used. These must be setup and configured at host level (server side).
What are the advantages of persistent object caching? #
- Improve database efficiency: Cut down on unnecessary query executions, reducing database server strain.
- Improved hosting performance: Make the most of your web hosting hardware, with resources served from additional powerful servers between the content and the consumer.
- Improved user experience: Faster and improved accessibility for users lead to happier visitors and improved engagement.
- Boost your SEO: Improve your core web vitals with faster loading response times (TTFB and thus FCP), a ranking in search performance.
Which Persistent Object Caching should I choose? #
This depends on your preference and your hosting environment. Redis and Memcached are the most popular of persistent object caching solutions, with both featuring WordPress plugins to make the connecting between your server and your WordPress install easier.
There may be limitations with either solution if using a shared hosting solution or particular server setup. It’s best to consult with your hosting provider.
I need help setting up my persistent object cache? #
The first step is to check with your host. Most managed WordPress hosting providers should provide some type of persistent object caching support. It may be as simple as turning it on in your hosting dashboard. They may even be able to assist with the process or even set it up for you.
You’ll also find some supporting setup material below based on some of the popular persistent object caching solutions.
- Redis: First setup Redis on your server before then installing and activating the Redis WordPress plugin. You’ll find some guidance on the plugins installation page.
- Memcached: You can follow the installation guide on the Memcached GitHub repository, before then installing and activating the WordPress plugin.
- APCu: Your hosting provider may support APCu. After enabling at host level you can use a plugin such as W3 Total Cache to seamlessly integrate with your WordPress site. Here you’ll find additional information with the W3 Total Cache plugin. An alternative to installing a plugin is to follow the steps in this GitHub repository.
Note that we don’t provide support for queries in relation to setting up any of the above within the AMP plugin support forum. Please refer to official support material or if you need further assistance talk with your web hosting provider.
I already have a caching plugin, isn’t that enough? #
While your existing caching plugin may be sufficient, if you’re looking to take advantage of the in-built WordPress object cache check whether your existing plugin can connect with your server side persistent object cache. Many third party plugins provide page caching only. These plugins can work alongside a persistent object cache. Note that you may need to apply particular configurations to ensure your page caching plugin doesn’t interfere with your persistent object cache. Reach out to your page caching plugin provider should you encounter any issues.
Caching is hugely important for any website, in particular for content management systems such as WordPress. With all the highly dynamic features WordPress provides, a suitable persistent object caching solution can provide excellent performance benefits, even for your AMP URLs.
Additional resources: #
Interested in learning more about caching? Visit the below resources.
- WordPress Handbook – Performance / Caching – WordPress.org
- WordPress at Scale – Object Caching – scalewp.com
- Everything You Need To Know About WordPress Object Caching – WP Astra
- What is Object Caching and How to Use It With WordPress – WP Rocket
- Persistent Object Caching – WP Tavern
- How to Use Redis as a Persistent Object Cache for WordPress – Kinsta
- Object Cache in WordPress – WP Engine
- HTTP Caching – Developers.google.com
- Prevent unnecessary network requests with the HTTP Cache – web.dev
- HTTP caching – Mozilla org
- Object Caching In WordPress – Codytek.com