If you have hosted any WordPress websites then you almost certainly have heard of ‘caching’. Many dedicated WordPress hosts will offer caching of some type or form and you’re also spoilt for choice when it comes to caching plugins. So, what exactly is caching and how does it help your website?
What is Caching?
WordPress is a dynamic system that generates viewable web pages for your end-users. The process it runs through to do this is pretty complex and involves pulling information from your website database. Queries go back and forth and the information pulled from the database is rendered as the final web page that everyone sees. Each time a web page is generated, your hosting has to call on a number of server resources to carry out this process. Server resources are limited and if you have a large amount of traffic this can cause problems. This is because the server won’t be able to keep up with all the demands being made on it to run the processes required by WordPress to render a web page.
To get around the issue of WordPress continually making calls to the database, and in doing so placing a burden on the server, caching is used. Caching is the term used for creating static copies of your page or post which are then served up to the end-user.
A software or hardware component is used to temporarily store values and retrieve them faster in the future. Values such as MySQL queries, or compiled PHP bytecode as well as duplicate data, such as HTML and images. Pretty much everything, really.
In effect, WordPress runs the processes required once to generate the page the first time someone visits it. This page is then cached and future visitors retrieve the cached content as a static page. Caching components are usually memory, but can be anything that can be faster than conventional storage.
But how much performance improvement can you gain? It all depends on how much data you can cache but generally speaking, performance improvements at the magnitude of one whole second, are not uncommon.
The Main Benefits of Caching
There are two key benefits of caching your WordPress website:
Data Retrieval Speed
Because the server only has to provide a static copy of a web page, the number of processes it has to run are far fewer. This results in much faster load times for websites that are cached. Speed is critical for a website. Not only will your website users abandon your site if it takes too long to load but Google will also penalize you resulting in lower rankings.
Server Load Reduction
Because the server only has to render a web page once before it is cached, each subsequent request for that page only requires a static copy to be served. This means the load on the server is significantly lower which is especially helpful during traffic spikes when, if the server was forced to render each page request, it would likely crash.
The Main Problem with Caching
Caching is a great option for almost all WordPress websites and the performance gains can be significant. This isn’t to say however it doesn’t come with problems, with the primary issue being that updates made to the site are not reflected in the live version that is being shown to your website visitors.
Keeping Cached Data Up-to-date
As discussed, a caching system saves a static copy of your website page or post. Because WordPress is dynamic this content may change for a number of reasons. The first is a user update whilst the second may be an update pushed out by some dynamic code (such as the date changing in the footer of your website). In either situation, you are going to want this fresh content to be reflected on the live version of your website.
Caching can sometimes mean this doesn’t always happen as the caching engine may fail to see the changes made to the page and as a result continues to serve the ‘old’ static copy of your website.
Try our Award-Winning WordPress Hosting today!
This is often a problem for developers who are making changes to the theme code of their live site. The caching plugin won’t spot these updates meaning that one thing ends up showing on the developer’s screen but another on the end-user screen.
How well your caching works and whether or not it does a good job of spotting these updates depends on the caching solution you chose to deploy.
In all cases though, this problem can be easily fixed by ‘flushing’ the cache. This means telling your cache to clear itself. It will then rebuild and move forward to serve up the correct up-to-date static version of your website.
Keep in mind though that whilst flushing the cache is an easy win solution for ensuring the correct version of your website is displayed, it does come with the downside that the entire cache has to be rebuilt. This can place a significant strain on your server, especially if you have a large website. As such, it’s sometimes preferable to clear the cache of just a single page or, better still, to move to a more sophisticated caching solution that does a better job of updating itself.
What can be cached?
There are several levels, depending on how far you want to go in optimizing your website using caching.
The first way is to cache the HTML page itself. There are many WordPress cache plugins like WP Rocket and W3 Total Cache that do that and much more. These plugins cache the result of the HTML output saving time for future requests. Additionally, every plugin gives you a cache invalidation mechanism so you can serve uncached content when wanted.
Another technique is to “minify” HTML, that is, to make it smaller. It is the process of removing extra characters from code, such as white space, comments, and unused code, to make the code smaller. To reduce the size even further, you can combine multiple files into one. This gives you a couple of kilobytes per page, but it adds up over time.
OpCaching is a technique whereby PHP takes the source PHP files and compiles them into an intermediary form, called bytecode. Bytecode is like a computer’s machine code, but it refers to machine code that is executed by a “virtual machine” (this case, PHP’s) rather than by a real one. Since it is machine code and resides in memory, it can be executed far quicker than having the PHP interpreter parse a command at a time and execute it.
Caching, at that level, stores these bytecode data into memory, so that your application can be executed faster. You need to have access to the PHP configuration file in order to have PHP OpCache enabled.
PHP Object Cache
This is caching that is done on the language’s OOP level. PHP is an object-oriented language, which means it uses the concept of “objects” to describe logic, data, and ideas. As your application runs, these objects are constantly being created and destroyed (dynamically, by a subsystem called the garbage collector). The process of creation and initialisation of these objects takes time. So object caching solves this by caching the objects themselves.
This is implemented via plugins such as Memcached and the assorted ones for Redis. Redis is a powerful in-memory data structure store that can be used as a database. Memcached is a distributed object-caching system. Both of them are excellent choices for doing caching at that level.
You will need to have access to PHP’s configuration in order to enable PHP Object caching. You will also need access to a Redis or Memcached instance.
MySQL Query Caching
MySQL Query Cache is the same idea but it is applied at a database level. The database returns a set of data according to the query that was entered. If you can cache the results of these queries, then the next time someone uses that query they will get the data much faster because they would reside cached in memory. For that, you will need to have access to the database server.
In order for all of these to be properly set up and maintained, a lot of things are required. Technical knowledge, time, and even money, if you lack experience. But we can help with all of that.
You have two main choices when it comes to caching for your WordPress website… to use a caching plugin (we’ve suggested some below) or to choose a managed WordPress host that offers caching as part of their platform.
Plugins offer a quick, easy and often free way to add caching to your WordPress site. As with most plugins, they vary in quality however and can require some expertise to set up and manage. Performance will likely vary significantly from plugin to plugin and you’ll need to carefully test to ensure you’re getting the results you expect from the plugin in combination with your hosting.
Caching offered by a managed WordPress host (like Pressidium) can often be more reliable as it’s been carefully developed and tuned to work with their hosting setup. As it will also likely operate at the server level it will almost certainly be faster. It should also require zero setup on your part and work ‘right out of the box’.
If using a managed host like Pressidium isn’t for you and you want to go it alone on the caching front then try out one of these caching plugins.
W3 Total Cache
With 1+ million active installations, W3 Total Cache is certainly a popular choice. Boating of at least 10 x improvement in overall site performance when fully configured, it is a great way to boost your page load speeds whilst reducing server load. Extensively tested, it should also work with most web hosts. Just be prepared to spend some time setting it up as it can be a little complex to get started with.
WP Super Cache
With an impressive 2+ million active installations, WP Super Cache is a leader in the caching plugin market. Developed by Automattic, the team behind WordPress itself, you can be confident it should deliver an excellent caching solution for your WordPress site. It’s very simple to set up with a limited range of customizations available making it the ideal choice for those of you who just want to load it up and get going asap. It’s also under regular development giving you the comfort that it should stay up-to-date and secure.
Whatever option you choose, WordPress caching is an absolute must for almost all WordPress websites. If you’ve yet to add caching to your site, then it’s one of the easiest wins for performance improvements you can do and well worth the time needed to get it setup.
How we solve everything with Pressidium’s Multilayer Caching.
The answer is simple. We have implemented caching everywhere: on all layers of WordPress.
For HTML output we implement two layers of caching, hot and warm. These layers are part of our adaptive cache engine. Our engine can also profile your site and enforce the most efficient caching rules. But, we’ll go into more details about this in another article. So the Hot cache is data that resides in-memory and can be accessed quickly. The Warm Cache is data that resides in state-of-the-art SSD disks. This increases overall cache-hit ratios and results in your site performing significantly better over conventional storage.
For our enterprise clients, we have built an object caching system using the excellent in-memory data structure store Redis. Finally, MySQL Query caching. This is enabled by default and monitored constantly by our DevOps. MySQL Query Caching can give you valuable information regarding your website’s performance.
It is important to note that all of these are implemented in our Platform’s backend, and not through some WordPress cache plugin. This means that a) we use external servers for storage, so we don’t burden your webserver’s resources and b) we store data in memory that is faster to access than disk.
Whatever your caching needs and budget, we can deliver.