There are four caching options within W3 Total Cache: Object caching, Page caching, Database caching, and Browser caching. What’s the difference between all these options? What do they all mean? Why does it matter? All were questions we had when we installed the plugin, so we thought we’d share the answers we found with you.
What is caching, again?
Caching is the act of storing data in such a way that future accesses to that data are faster.
Typically caching involves moving data from a slow location to a fast one. The hard drive has hundreds of times more storage space than RAM, but RAM is thousands of times faster to access than the hard drive. Caching is used to try and get the best of both worlds by making copies of the most frequently accessed items from slow memory and storing them in fast memory.
Caching can also be used to store dynamically generated content like PHP-created HTML pages and database query results. Rather than create the content over and over with each request, the result can be cached and served up directly, freeing up valuable resources and making everything faster. The caches we’re talking about today aren’t exclusive to W3TC, but for the purposes of this article all apply to caching for a web server.
Browser Caching
As the name suggests, Browser Caching is caching done by the user’s web browser. Rather than download the same resource again and again, the user’s computer can simply draw upon files it already has. This reduces the number of times the server needs to handle requests, and tremendously speeds up the time a page takes to load when requested multiple times by the same user. Browser Caches hold HTML files, images, and other downloaded resources.
A web server can control what does and doesn’t get cached by the browser (and for how long) by modifying various headers in the HTTP response for each item. Setting values such as “expires”, “etag” (or “entity tag”), and “cache-control” give the server a great deal of control over what the browser will cache. Click here for more detail on what these headers are and what each of them mean.
Object Caching
An “Object” is a location in memory that has a value and can be referenced by an identifier. Data structures, functions, databases, variables, virtually anything in memory can be an Object. Thus, Object Caching is the caching of these abstract data objects. To that end, all the more specialized types of caching that follow this type can all be thought of Object Caches that only store a particular type of Object. Many WordPress plugins can take advantage of generic Object Caching to store unique values that don’t necessarily fall into any predefined category.
Page Caching
In WordPress, each page is dynamically generated using PHP scripts. This page generation takes quite a bit of time, and the server has to recreate the page every time a request is made for it. For popular pages that don’t change very often, it would be nice if we could save these generated pages in memory so the server won’t have to work as hard. Fortunately, Page Caching is exactly that: a way to store dynamically generated pages so they don’t have to be generated as often.
Page Caching is not an end-all solution, however. Pages that are intended to be user-specific such as a favorites list in a shop, or pages that have content that updates frequently such as a home page are not good candidates for this type of caching. When used on more static pages though, enabling Page Caching on a website can have a dramatic impact on both front-end performance and scalability.
Database Caching
Just as Page Caching stores dynamically generated pages into memory for faster access, Database Caching stores the results of database requests into memory so those results won’t need to be generated again. This makes frequent database queries much faster to return, and is especially useful when the database in question is on a different server entirely.
Summary
While each of these cache types in W3TC stores different things, they all function in a similar manner: Store resources in different places for faster access. These caches are exactly what it says on the tin: Page Caching is for storing copies of dynamically generated WordPress pages, Database Caching is for storing copies of database query results, Object Caching is for storage of generic “Object” data, and Browser Caching is caching directly on the user’s machine through the browser. Understanding how each of these work, what they are storing and why they are storing it will help you decide how to configure each of them, or even whether or not to turn them on in the first place.