Which Is Better: Object Caching or Database Caching in WordPress?
To make your WordPress-based website load faster, you might decide to use caching. Caching plug-ins offer many options for caching parts of your pages on the server, and you may choose to employ a single caching strategy such as object or database caching, or use them together. While object and database caches house similar parts of your pages, using one over the other is dependent on the characteristics of your site and server.
-
How Caching Works
-
In a default WordPress install, each page is assembled on demand from its various configuration files, database objects, images and other parts. When you employ caching, some of the parts are assembled on your server. You can cache database objects, page elements or even entire HTML pages this way. In addition, WordPress offers the ability to cache database objects in memory.
Object Caching
-
When WordPress displays a page, it may use the same database object in multiple instances. For example, the author's name might appear at the top and bottom of the post, and a widget might list the name along with a few other posts by that author. WordPress's built-in object caching stores a page's database objects in memory, and if the page needs to reuse an object, WordPress will pull the object from memory instead of making another query. This cache is not "persistent," stored only until the page is finished loading. To use persistent memory-based object caching, your site must be on a dedicated server. Disk-based persistent caching is usually much slower than memory-based caching.
-
Database Caching
-
Database caching works in a similar fashion to object caching, but while object caches are best stored in memory, database caches are disk-based, containing all the query results for a specific page for insertion in the assembled WordPress page. Database caching is persistent, and the cache resides on your server's disk, so if the disk is slow, a database cache may also cause slower page load times than allowing WordPress to query the database directly.
Best Practices
-
Used properly, both the object and database caching methods can speed loading of your site, depending on the site's server and visitor demand. However, while native WordPress object caching can speed page loading, a persistent disk-based object cache can actually slow your pages down. You may also see better speed gains using page caching to store recently browsed pages as static files or a content delivery network to serve linked images and other content from a secondary server. HTTP Expires headers will help Web browsers to retain page elements in their caches, improving your visitors' experience without server-side caching. Headers can be used in combination with any other method.
Implementation and Testing
-
The W3 Total Cache plug-in enables you to try combinations of caching methods. Enable WordPress's native object caching as a first step; most sites see a significant speed increase using this option alone. To easily test the difference in page loading speed with different caching options, use a speed test like YSlow or Google Page Speed. Each time you change your caching settings, perform a speed test as a comparison.
-
References
Resources
- Photo Credit Jack Hollingsworth/Photodisc/Getty Images