If you are into WordPress, big chance you have seen the term caching. Maybe on a blog post about performance, or advertised by a hosting provider. But what is caching exactly?
So, what is caching? The Basics
Caching is a technique used to store data in a temporary storage area, called a cache, so that it can be accessed more quickly in the future. When data is retrieved from the cache, it is called a cache hit, and when data is not found in the cache and has to be retrieved from another source, it is called a cache miss.
Usually, a cache hit will load much faster than a cache miss.
Types of Caching
There are different types of caching, including web (or page) caching, application caching, object caching, and database caching. Web caching is used to store the content of web pages, such as HTML documents and images so that they can be served more quickly to users. Application caching is used to store data generated by applications, such as data from a database or results of computations, in order to speed up the performance of the application. Database caching is used to store data from a database in a cache in order to reduce the number of database queries that need to be made.
I will explain more about these types of caching in the upcoming section “Caching in WordPress”.
Performance Benefits of Caching
Caching can significantly improve the performance of systems by reducing the amount of time and resources needed to retrieve data. It works by temporarily storing a copy of the data in a location that is faster to access, such as in memory or on a hard drive, so that it can be retrieved more quickly in the future.
When the data is needed again, it is first checked in the cache to see if it is available. If it is, the data is retrieved from the cache, which is much faster than retrieving it from the original source. If the data is not found in the cache, it is retrieved from the original source and then stored in the cache for future use.
The performance difference for sites with caching turned on and off is substantial. This is a typical example of how many requests a site can handle with caching on and off:
Caching On | Caching Off | |
---|---|---|
Requests per second | 2400 | 40 |
As you can see, a typical WordPress site with caching can handle up to 60 times more visitors than one without caching!
Caching in WordPress
In WordPress, there are several layers of WordPress caching possible. These are the most commonly used ones:
- Page Caching: Page caching is a technique used to improve the performance of a website by storing frequently accessed web pages in a cache. This can reduce the time it takes to retrieve and display the page, which can improve the user experience and reduce the strain on the server’s resources. Page caching is in most cases a no-brainer unless your WordPress site is very dynamic. Examples of dynamic sites are sites that require a login, such as fora.
- CDN Caching: A Content Delivery Network (CDN) is a distributed network of servers that are used to deliver content, such as web pages, images, and videos, to users based on their geographical location. CDN caching is a technique used by CDNs to improve the performance of a website by storing copies of the content on servers located close to the users who are requesting it. CDN Caching is great for international websites with visitors from many countries.
- Object Caching: Object caching is a technique used to improve the performance of an application by storing frequently accessed data in a cache. This can reduce the number of times that the application needs to access the data from its original source, such as a database or a file system, which can improve the performance and scalability of the application. It will greatly improve performance when you have a large WordPress database.
- Opcode Caching: Opcode Caching stores the compiled version of PHP code (opcodes) in a cache, improving WordPress performance.
- Browser caching: Browser caching is a technique used to improve the performance of a website by storing frequently accessed resources in the cache of a user’s web browser. This can reduce the amount of time it takes to load the page, as the resources can be retrieved from the cache rather than downloaded from the server. In other words, if the file is already on your computer, you don’t need to download it again.
Applying Caching in WordPress
Now that the benefits of caching are clear, how do you apply WordPress caching? Usually, caching is applied in several ways:
- By installing a WordPress caching plugin. There are several caching plugins available.
- By using a good WordPress host, which has caching preconfigured, such as Kinsta.
Overall, caching is a useful technique for improving the performance of systems by reducing the time and resources needed to retrieve data. It is widely used in a variety of applications and systems to improve performance and reduce the workload on servers and other resources.