Object Cache in WordPress
Caching helps load to your server by saving the data of repeat requests. This makes you site more stable, faster and more scalable as your business grows. There are two primary types of caching WP Engine servers offer: page caching and object caching. While page caching is always on by default, object caching must be enabled manually.
Object caching can give you a speed boost by reducing the time it takes to access the database. Learn about the object cache, why we recommend it and when it might cause issues.
About Object Cache
Page cache – Stores the previously generated code necessary to load a page.
Object caching – Stores the results of queries to your site’s database.
Similar to regular page requests, queries can stack up and cause slowness on sites if too many are run at a time. An example would be if you have redirects configured through a WordPress plugin. Any time a page of your website is loaded, WordPress must load the full list of redirects by making a database query.
Object Caching takes repeated queries like this and stores the results of those queries in Object Cache. This speeds up the operation so your server doesn’t have to generate a new result every time, and also helps your server’s health. The server stays healthier because it spends less time and energy searching for the same thing over and over.
In the graphic above a query request is received by the site (shown in yellow). The server first checks to see if it has any results for this query in the Object Caching layer. If it doesn’t, it sends the query to be run in the database.
On the way back to show the results of that query (shown in orange), the server stores a copy of the results in the Object Caching layer. Next time the query is run, the server will not have to reach back into the database for the same information.
Transients and Options
Transients can place information in the database allowing for quick access to persistent data storage across page loads. Transients differ from options set by plugins and themes in that transients are meant to be used as temporary storage, never long-term. As we have a object cache buffer size limit, over-filling it with autoloaded data (transients or options) can lead to issues (performance or otherwise) for your website. Therefore, it’s important to understand how your site is using transients and options stored as “autoload” when using WP Engine’s Object Caching.
Enable Object Cache
The object cache layer is enabled independently for each environment. Depending on server type, we may use a drop-in plugin or an mu-plugin for object caching.
NOTE
The default state of object cache on new environments enabled.
- Login to the User Portal
- Select the environment name you’d like to enable object caching on
- Click Caching
- Locate Object Caching and toggle to On
Disable Object Cache
The object cache layer is disabled independently for each environment.
- Login to the User Portal
- Select the environment name you’d like to enable object caching on
- Click Caching
- Locate Object Caching and toggle to Off
Purge Object Cache
Page cache automatically clears on a regular basis, but object cache is not cleared out at a specific time interval.
Instead, an algorithm is used to determine which query result in the object cache is the “least recently used” and remove it. Object cache only purges these query results from its cache once its storage space is used up.
The object cache size buffer is 1Mb.
It’s possible that you may have added content to your site, and specifically want queries to reflect that new content. In this case, you’d want to manually purge cache.
Object cache can be purged from the WP Engine User Portal, or from the wp-admin dashboard of your website.
Object Cache and 502 Errors
Object Caching is a super beneficial tool to use on the WP Engine platform, but it does come with some caveats. If you enable Object Caching and then start to see 502 errors on your site, this is most likely indicating that your wp_options
table is storing a large amount of autoloaded data.
Autoloaded data is content stored in your site’s database – specifically, in the wp_options
table. This is data that your site is required to load on every single page load. Some content (like your site’s siteurl, or home records) should load on every page, but not everything needs to!
Object Caching stores these autoloaded values as one long row. If the content that’s autoloaded surpasses the amount Object Caching can handle, then it rejects the request. WordPress, requiring the autoloaded data, sends the request again, and this causes a loop which eventually ends in a 502 error on the site.
Remember, the object cache has a buffer, or storage, size of 1Mb. This means autoloaded data should stay below 800,000 bytes to maintain a healthy website.
Temporarily disabling object caching can resolve error messages while the autoloaded data is reduced.
Check out our guide for identifying and reducing autoloaded data.
NEXT STEP: Learn more about optimization opportunities for your WordPress website