WordPress Caching: How it Works?

Welcome to the latest installment of our WordPress Caching series, where we will explore the ins and outs of how WordPress caching works. Before we dive into this topic, it is important to note that you should have a solid understanding of the previous topics in this series, as this chapter builds upon that knowledge. In this article, we will discuss the two primary types of caching protocols available: client-side caching and server-side caching.

Client-Side Caching

When you visit a website, your browser downloads non-textual, static data such as images, CSS, and Javascript files. Once these files are downloaded, your browser will not re-download them every time you refresh the page. Instead, it will serve the data from the local cache, which is the cached data saved on your computer’s hard disk. This process is known as client-side caching and is used by almost every modern website. By reusing cached data from the client’s computer, client-side caching helps prevent data redundancy and saves server resources and time. It is recommended to clean your browser’s cache periodically to save space and improve performance.

Server-Side Caching

Server-side caching includes all the various caching protocols used in WordPress caching. These protocols include page caching, database query caching, object-based caching, and opcode caching. Let’s take a closer look at each of these protocols and see how they can save precious computation time and speed up your website.

Page Caching

Page caching is the simplest of all the caching protocols. It refers to the process of saving dynamically generated HTML files in the server’s hard disk or memory (RAM), commonly known as the “cache.” When a request is made, the server serves the cached data (i.e., reuses previously generated data) instead of executing PHP code and MySQL database queries. This saves the overhead of executing PHP code and MySQL database queries.

Database Query Caching

Databases are huge and resource-hungry, and they are the heart of every company, online or otherwise. WordPress is heavily reliant on its database, and every query takes time. When data isn’t being altered in the database, making queries to retrieve the same data is like re-downloading the same images over and over again. Saving the results of a query in the local storage makes sense, and this process is called database query caching. However, once the database is updated, it is essential to delete the previously saved database cache and re-cache the database query results to eliminate irrelevant or erroneous results.

Object-Based Caching

WordPress has an internal caching system that includes several subsystems, such as the Caching API, Object Cache, and Transient API. The WordPress core allows plugins to control this caching system to reduce the number of database calls. This is an advanced topic and not relevant to everyday users.

Opcode Caching

Opcode caching refers to the saving of compiled PHP code between every request. PHP code is a list of instructions for the compiler to use. For a PHP code to execute, the PHP compiler must compile the code first and generate the executable code for the webserver to execute. Caching the output of the PHP compiler for multiple executions is what opcode caching is all about. This is internal stuff that you shouldn’t worry about.

Local Storage – Primary Versus Secondary

To implement server-side caching of any form, the data must be stored in local storage. Local storage can mean either the server’s hard disk or the server’s primary memory (RAM). RAM is orders of magnitude faster than hard disks but more expensive. Where you save the cached data makes a huge difference. If it’s on a hard disk, it’s slower than when stored in RAM. The speed of the HDD matters, and server hard disks range from 7,200 RPM to 15,000 RPM and may have different RAID levels. You also have SSDs. The cached data location has a severe impact on speed.

Conclusion

Now that you have a good understanding of the various WordPress caching protocols, let’s move on to the centerpiece of our post series: How to Implement WordPress Caching. If you have any questions or suggestions to improve this chapter, please feel free to ask or share them. We’d love to hear your thoughts!

Stay in Touch

spot_img

Related Articles