WpW: Caching 101
Welcome to another installment of WordPress Wednesday!
Today’s Topic: What is Caching?
Today we are going to begin a series-within-a-series, and talk about the basics of caching: what is a cache? Why is it beneficial to cache your WordPress site? What types of caching are available to web applications? And then we’ll get into the basics of our own caching solution: LiteSpeed Cache, affectionately referred to as LSCache for short. We’ll also talk about how LSCache is different than other WP caching solutions available, and what that really means for you.
It’s a meaty topic, so we’re going to split it up into a few smaller chunks for easier digestion. Today, let’s start with the basics of web app caching, as they pertain to WordPress.
What is Caching?
Generally speaking, a cache is a mechanism for storing data in such a way that it is easier or faster to retrieve than the original source.
WordPress sites consist of dynamic pages that are built with PHP. The pages of a WP site don’t exist anywhere in the file system; they are constructed on-demand through PHP, and then served to the visitor as HTML. Along this path, there are a few places that are resource-intensive and ripe for the caching.
Types of Cache
Cache can be stored on the visitor’s own device (client side), on the website’s network (server side), or halfway around the world (via a content delivery network). Some sites may employ all of these methods, while others have the need for very few.
Most of the work of generating and delivering a web page is done on the server side, so it make sense that more of the opportunities to increase efficiency would also be here. There are four major types of server-side caches available to WordPress sites.
A database cache saves time and resources related to the execution of database queries. WordPress relies on its database for basic information about the site, and it asks for this same information often. A database cache stores the query results so that they may be referenced again and again without the need to repeatedly access the database.
An object cache saves time and resources related to the computation of objects. WordPress has a built in object cache mechanism with a defined class and set of functions that can be used to add, access, remove, or otherwise manipulate the object cache. An object cache doesn’t stick around for long. By default, it’s only relevant for the duration of a single request. It’s used to store data that is needed multiple times in a request, but is considered expensive to re-compute. Often, the object cache stores database queries, which is why it is sometimes mistaken for a synonym of “database cache.”
An opcode cache saves time and resources related to the execution of PHP code. Before PHP can be executed it must be compiled. An opcode cache stores this compiled code at the server level so that it may be reused without recompiling. The next time a request is sent that requires that PHP code to be executed, it can save the compilation step and just run the code that was saved in the opcode cache.
LiteSpeed Cache is a page cache. Page caches, too, save time and resources, and they do so by storing the full content of dynamically-generated pages so that static copies may be served to the user. A page cache allows the server to bypass PHP and database queries altogether. The other types of cache can be helpful while building up your page cache, but once there is a fresh, well-managed page cache in place, there is little need for database, object, or opcode caches.
Content delivery networks
Content delivery networks (or, CDNs) store static website content remotely in servers all around the world. The content may then be served to a site’s visitor from the server that is physically closest to that visitor’s location. The closer the server, the less time the data takes in transit. CDNs are great when it comes to static content, but are lacking when you have a dynamically-generated site such as WordPress, as the content requests must still hit the WP backend.
Until Next Time…
So, there is your overview. At this point, you should understand what types of caching are available for your web apps, and why you might want to use them. Our next article in the Caching 101 series will focus specifically on our solution: LiteSpeed Cache. We’ll talk about how it works, why it’s different than other WordPress page-caching plugins, and what benefits those differences get you. Be sure to meet us back here for that!
Have some of your own ideas for future WordPress Wednesday topics? Leave us a comment!
Don’t forget to meet us back here next week for the next installment. In the meantime, here are a few other things you can do:
- Subscribe to the WordPress Wednesday RSS feed
- Download LiteSpeed Cache for WordPress plugin
- Learn more about the plugin on our website