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.

object-caching-layer

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.


Enable Object Cache

The object cache layer is enabled independently for each environment.

  1. Login to the User Portal 
  2. Select the environment name you’d like to enable object caching on
  3. Click Caching
  4. Locate Object Caching
  5. Toggle Enable object caching

Disable Object Cache

The object cache layer is enabled independently for each environment.

  1. Login to the User Portal 
  2. Select the environment name you’d like to enable object caching on
  3. Click Caching
  4. Locate Object Caching
  5. Toggle Disable object caching

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

Code-level performance analytics

Application Performance provides real-time, code-level visibility to help you troubleshoot faster, optimize WordPress experiences, and increase development agility.