Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared hosting Managed WordPress Cloud hosting VPS hosting By reader location Hosting finder
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Blog Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Explainers · Explainer

What Is Object Caching? A Plain Explanation

What Is Object Caching? A Plain Explanation

Short answer

Object caching stores the results of expensive database lookups in memory, so WordPress can reuse them instead of asking the database again. By default the cache lasts for one request only, and a persistent cache backed by Redis or Memcached keeps values across requests. It speeds up database-heavy pages, above all for logged-in visitors.

Key takeaways

  • Object caching stores database answers in memory so WordPress can reuse them instead of asking the database again.
  • By default the WordPress object cache lasts for one request only; a persistent cache keeps values across requests.
  • A persistent cache needs a drop-in file named object-cache.php in wp-content plus a Redis or Memcached server.
  • Redis answers in sub-millisecond time and is the most common backend for WordPress object caching.
  • A page load with 2,000 Redis calls can take 2 full seconds, so more cache calls are not always better.

What is object caching?

Object caching stores the results of expensive database lookups in memory, so WordPress can reuse them instead of asking the database again.

The WordPress developer docs describe the object cache as a way to save trips to the database: it stores cache data in memory and makes it available by a key.

Every WordPress page asks the database for the same things: site settings, menus, widgets, and post data. The object cache keeps those answers in memory for the next request.

It is a short-term memory, not a second copy of your site. When the cached answer expires or changes, WordPress asks the database again.

How does the WordPress object cache work?

WordPress stores each cached value under a key, and code asks for that key before it runs a database query.

The developer docs list the functions plugins use: wp_cache_get() reads a value, wp_cache_set() stores one, wp_cache_add() stores one only if the key is empty, and wp_cache_delete() removes one.

The get() method counts hits and misses. On a hit it returns the stored value, and on a miss it returns false and the caller runs the query instead.

Values can sit in groups, so the same key can hold different values in different groups. The default group is called default.

The cache class is named WP_Object_Cache, and it lives in wp-includes/cache.php. It has been part of WordPress since version 2.0.0.

Use the Transients API instead when you need a promise that data will be cached, because the object cache gives no such promise.

What is the difference between persistent and non-persistent caching?

By default, the WordPress object cache lasts for one request only, and a persistent cache keeps values across requests.

The developer docs state that by default the object cache is non-persistent: data stored in the cache lives in memory only for the duration of the request.

A persistent cache stores values in an outside memory store such as Redis or Memcached, so the next request can read them back.

You switch to a persistent cache with a drop-in file named object-cache.php in the wp-content folder. When that file exists, WordPress uses it instead of the built-in cache.

Without a persistent cache, every page view must ask the database for everything about the site, according to the SQLite Object Cache plugin page on WordPress.org.

FeatureBuilt-in cachePersistent cache
Lives forOne requestAcross requests
StoragePHP process memoryRedis, Memcached, or SQLite
Setup neededNone, built inobject-cache.php drop-in plus a cache server
Survives the end of a requestNoYes
Shared by all PHP workersNoYes

Our guide on page cache vs object cache explains how the two layers work together.

What are Redis, Memcached, and APCu?

Redis, Memcached, and APCu are three memory stores that can hold the persistent object cache, and Redis is the most common choice for WordPress.

Redis is an open-source, in-memory data structure store used as a database, cache, message broker, and streaming engine, and it answers in sub-millisecond time.

Redis stores data as key-value pairs, and it supports strings, hashes, lists, sets, sorted sets, streams, JSON, and vector sets.

Memcached is a free and open-source, high-performance, distributed memory object caching system that speeds up dynamic web apps by easing database load.

Memcached stores small items as a key, an expiry time, and raw data, and it drops the least recently used items first when memory runs out.

APCu is a PHP key-value store saved in memory, and the WordPress developer docs list an APCu object cache plugin as a persistent backend. It runs inside PHP on one server, so it suits single-server sites.

Our guide on Redis vs Memcached for WordPress compares the two main options in detail.

How is object caching different from page caching?

Page caching stores finished HTML pages, while object caching stores the database answers WordPress uses to build those pages.

A page cache serves the same finished page to every visitor. The object cache helps while WordPress is still building the page.

A logged-in visitor sees a page built for them, so a page cache often skips them, and the object cache does the work instead.

The SQLite Object Cache plugin page makes the same split: object cache entries are data objects for WordPress, not chunks of web pages ready for browsers.

Most fast sites use both layers. The page cache handles anonymous visitors, and the object cache handles the database work behind every page.

Our guide on what server-level caching is covers the other cache layers on a host.

How do you set up object caching on WordPress?

You set up object caching by installing a cache server such as Redis, then adding a plugin that connects WordPress to it.

The Redis Object Cache plugin page warns that you must install the Redis server before using the plugin.

Its setup runs in 4 steps: install and configure Redis, install the Redis PECL module or the Predis library, add object-cache.php to the wp-content folder, and let the plugin connect to Redis at 127.0.0.1 on port 6379 by default.

You can change the host, port, and database with the WP_REDIS_BACKEND_HOST, WP_REDIS_BACKEND_PORT, and WP_REDIS_BACKEND_DB constants.

Many managed hosts already run Redis, so check your host's panel or docs before you install anything yourself.

Our guide on how to set up Redis object cache in WordPress walks through the setup step by step.

How do you check if object caching is working?

Check for the object-cache.php file in your wp-content folder, and check the plugin's status screen for a live connection.

If the drop-in file is missing, WordPress falls back to the built-in cache that lasts one request.

The WP Redis plugin adds WP-CLI commands, including wp redis info, which reports details on the Redis connection.

The developer docs name the Debug Bar and Query Monitor plugins as tools that help you analyze the object cache.

Compare logged-in page load times before and after setup, using the same pages. A clear drop on member pages and in the admin area is a good sign the cache is working.

When does object caching not help?

Object caching does not help a small, quiet site, because the database is already fast enough and there is little to reuse.

It also does not fix a slow theme or a bad query. It stores answers, but it cannot make a bad query good.

The WP Redis plugin page warns that a page load with 2,000 Redis calls can take 2 full seconds of object cache transactions, so more cache calls are not always better.

A persistent cache is not a promise either. The developer docs advise using the Transients API when you need a guarantee that data will be cached.

If your host does not run Redis or Memcached, you cannot add a persistent cache without changing hosts or adding a server.

Our guide on how to reduce server response time in WordPress covers the other fixes to try first.

What are common myths about object caching?

Five myths about object caching confuse buyers, and each one falls apart against the docs.

Myth one: object caching and page caching are the same. They store different things, and most fast sites use both.

Myth two: object caching replaces the database. It does not. It only stores copies of answers, and the database still holds the real data.

Myth three: more caching always means more speed. Each cache call costs time, and 2,000 Redis calls can cost 2 seconds, as the WP Redis plugin page notes.

Myth four: installing the plugin is enough. The plugin needs a running Redis or Memcached server, and without it there is nothing to connect to.

Myth five: object caching fixes every slow site. It helps busy, database-heavy sites most, and a quiet site may see no change at all.

Frequently asked questions

Is object caching the same as page caching?

No. Page caching stores finished HTML pages, while object caching stores the database answers WordPress uses to build those pages. A page cache serves the same page to every visitor, while the object cache helps while WordPress is still building the page. Most fast sites use both.

Does WordPress have an object cache without any plugin?

Yes, and that is the normal setup. WordPress ships with a built-in object cache that lasts for one request, so the feature is always there. You only add a plugin and a cache server when you want the cache to persist across requests.

Should I use Redis or Memcached for WordPress?

Redis is the most common choice, because it is fast, widely supported, and well documented for WordPress. Memcached is simpler and also works well. APCu runs inside PHP on one server, so it suits single-server sites. Your host may already run one of them.

How do I know if my object cache is working?

First check that object-cache.php exists in your wp-content folder. If it is missing, WordPress falls back to the built-in cache. Then check the plugin's status screen for a live connection, or run wp redis info if you use WP Redis and WP-CLI.

Can object caching make a site slower?

It can. The WP Redis plugin page warns that a page load with 2,000 Redis calls can take 2 full seconds of object cache transactions. A cache call still costs time, so a plugin that caches too much can slow a page down instead of speeding it up.

Sources

  1. WP_Object_Cache WordPress Developer Resources
  2. Redis Object Cache WordPress.org
  3. WP Redis WordPress.org
  4. What is Redis? Redis
  5. Memcached Documentation Memcached

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

Written and checked byWPLegible Editorial Team Independent WordPress reviews and guides

Researched from the primary sources listed above and checked against our editorial rules before publishing.