Let’s talk a bit about the idea and the underlying concept of Caching on websites. We’ll describe what Cache is, explain why it’s essential for WordPress sites, and explore the various types of Cache for websites and web applications. Let’s get started…
What is Caching?
In general, Caching is a mechanism that allows us to store data in a specific way that enables faster and easier access to the information compared to fetching it from the source.
WordPress websites contain dynamic pages built using PHP. The pages of a WordPress site don’t exist as files in the file system but are generated on-demand using PHP and then served to users as HTML pages.
During this process, there are several places that require significant resources, and it’s precisely these places where Caching comes into play. To understand this, we need to grasp the different types of cache systems…
Types of Cache
Cache can be stored on the user’s device or computer (client-side), on the website’s server (server-side), or even on the other side of the world through a CDN (Content Delivery Network). Some websites can utilize all the Cache methods we describe, while others might use only a subset or none at all.
A. Client-side Caching
All modern web browsers support client-side caching. The user’s browser knows that certain files change infrequently, such as CSS, JavaScript, and image files, which can be stored locally in the browser’s cache. This allows for easy and fast access to these files without needing to download them from the server again.
B. Server-side Caching
Most of the work of creating and delivering web pages occurs on the server-side. Therefore, it’s logical that most opportunities to enhance efficiency will also occur on the server-side. There are four main types of Cache on the server-side available for WordPress sites:
1. Database Cache
Database cache saves time and resources related to executing queries to the database. WordPress relies heavily on the same database to obtain information about the site’s content, often requesting the same content repeatedly.
Database cache stores the results of these queries on the server, enabling quick access without the need to query the database again each time.
2. Object Cache
WordPress has a built-in mechanism for object caching, allowing adding, accessing, removing, or manipulating object cache. It’s important to note that object cache doesn’t persist for long and is relevant only for the duration of a single request.
It serves to store information that is required multiple times during the same request, saving valuable time on calculations. Object cache also occasionally stores database queries, which is why many confuse it with the database cache mentioned earlier.
3. OpCode Cache
Opcode cache saves time and resources associated with running PHP code. Before PHP code can be executed, it needs to be compiled. OpCode cache stores that compiled code on the server, allowing it to be reused without the need for recompilation.
The next time a request is made to run that same PHP code, it can be used directly from the opcode cache without the need for recompilation.
The top three types of caches will save resources for the server, but there will be little need for them after the process of generating static copies of pages by the Page Cache in the next section.
4. Page Cache
Plugins like LiteSpeed Cache and WP-Rocket are considered page caches. Similar to the other cache types, page cache saves time and resources.
It does this by storing the complete content of dynamically generated pages. Therefore, a “static” copy of those pages is served to visitors when needed.
Page cache allows the server to “bypass” much of the PHP process and database queries. While the other cache types assist in building those static versions of pages created by the page cache, once a fresh and well-managed page cache exists, there’s minimal need for the previous cache types mentioned.
Content Delivery Network (CDN)
A CDN stores static versions of website pages on servers distributed worldwide. These static versions are accessible to website visitors from a nearby server physically located close to the visitor’s location.
The closer the server is, the less time it takes to transmit the information, meaning those static versions are quickly accessible.
Using a CDN is excellent for static websites. However, it falls short in systems that generate dynamic pages like WordPress, as the demand for specific content still needs to go through WordPress’s backend.
In Conclusion
This was a general overview of caching systems. At this point, you likely understand the different types of Cache available for websites and web applications, and you might even consider using them.