ASHISH KANAJARIYA0%Preparing your experience
Skip to content

WordPress Redis Object Cache: A Practical Setup and Tuning Guide

Server cooling fans in a data centre, representing a WordPress Redis object cache

Page caching gets most of the attention in WordPress performance, and for good reason. It turns a full PHP page build into a quick file or memory lookup. But many requests can never be page cached: the WordPress dashboard, logged-in users, carts, checkouts, searches, REST API calls and background tasks. For all of these, the database is often the bottleneck. A WordPress Redis object cache is one of the most effective ways to lighten that load.

In this guide I explain what the object cache is, how a persistent Redis cache changes it, how to tell whether your site will benefit, and how to set it up and tune it. I also share the checks I use to confirm it is working, because an object cache that is installed but not used looks exactly the same in the dashboard as one that is doing its job.

What Is the WordPress Object Cache?

WordPress has a built-in caching layer called the object cache. When core or a plugin loads data, such as options, post objects, terms or user data, it can store the result with wp_cache_set() and retrieve it later with wp_cache_get(). This avoids repeating the same database query several times within one request.

By default, this cache lives only in PHP memory for the duration of a single request. When the page finishes, the cache disappears, and the next request starts from scratch. It still helps, because a typical page asks for the same data many times, but every new request must query the database again.

What a persistent object cache adds

A persistent object cache keeps that data between requests. WordPress supports this through a drop-in file called object-cache.php in the wp-content folder. When the drop-in is present, WordPress sends every object cache call to an external store such as Redis or Memcached. The first request loads data from the database and saves it in Redis; the following requests read it from memory in a fraction of the time.

Transients benefit too. When a persistent object cache is active, WordPress stores transients in the cache rather than in the options table, which keeps that table smaller and faster.

Why Redis?

Redis is an in-memory data store known for speed and reliability. It is a popular choice for WordPress because it is widely available on managed hosting and cloud platforms, it handles the small key-value lookups WordPress makes extremely quickly, and it offers flexible memory limits and eviction rules. Memcached is also a solid option and works on the same principle. Whichever your host supports well is usually the right choice. In this guide I focus on Redis because it is the most common setup I see.

Does Your Site Need a Redis Object Cache?

Since WordPress 6.1, Tools → Site Health can recommend a persistent object cache when your site looks large enough to benefit. That is a useful hint, and these situations are strong signs too:

  • WooCommerce stores, where carts, checkouts and account pages are always uncached.
  • Membership, learning and community sites with many logged-in users.
  • Slow admin screens, especially editing screens and list tables with many items.
  • Heavy REST API or AJAX usage, such as headless front ends, live search or filters.
  • Busy background processing, where cron and queues load WordPress many times an hour.

A small brochure site with full-page caching and few logged-in users will see a smaller benefit, because most visits never reach PHP. It is still harmless to add, but it is not the first optimisation I would reach for there.

Rows of server blades in a data centre, representing in-memory caching

How to Set Up a WordPress Redis Object Cache

The setup has two parts: a Redis server, and a WordPress drop-in that talks to it.

Step 1: Make sure Redis is available

Many managed hosts provide Redis with a toggle in the control panel. On a VPS, you install the Redis server package and the PHP Redis extension, often called phpredis. Ask your host if you are unsure; it is a common request, and most support teams can confirm the connection details quickly.

Step 2: Add connection settings to wp-config.php

The Redis Object Cache plugin is the most widely used drop-in. It connects to 127.0.0.1 on port 6379 by default. If your host uses different details, or if several sites share one Redis server, define them in wp-config.php:

define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_DATABASE', 0 );
define( 'WP_REDIS_PREFIX', 'mysite_' );

// Only if your Redis server requires a password:
// define( 'WP_REDIS_PASSWORD', 'your-password' );

The prefix is important on servers that host more than one WordPress site. Without a unique prefix or database number, two sites could read each other’s cached data.

Step 3: Install and enable the drop-in

Install and activate the Redis Object Cache plugin, then go to Settings → Redis and click Enable Object Cache. The plugin copies its object-cache.php drop-in into wp-content. If you prefer the command line, the plugin includes WP-CLI commands:

wp plugin install redis-cache --activate
wp redis enable
wp redis status

The status command should report that the drop-in is valid and the connection is established. If you use LiteSpeed Cache, it also offers object cache settings for Redis and Memcached under its Cache options. Use one object cache solution at a time, because only one object-cache.php drop-in can be active.

How to Confirm the Object Cache Is Working

Installing the plugin is not the same as getting the benefit. I always confirm three things:

  1. Status: wp redis status or the Settings → Redis screen shows Connected with a valid drop-in.
  2. Hit ratio: the plugin’s metrics, or a debugging plugin such as Query Monitor, show the percentage of cache lookups answered from Redis. After the cache warms up, a healthy site usually serves the large majority of lookups from memory.
  3. Fewer queries: compare the number of database queries on an uncached admin page before and after. A clear drop shows the cache is doing real work.

Site Health is a good final check. Once the drop-in is active, the persistent object cache recommendation no longer appears.

Tuning Redis for WordPress

A default Redis installation works, but a few settings make it more predictable on production sites.

Set a memory limit and eviction policy

A cache should never grow until the server runs out of memory. In the Redis configuration, set maxmemory to a sensible size for your site, often somewhere between 64 MB and a few hundred megabytes, and set maxmemory-policy to allkeys-lru. With this policy, Redis removes the least recently used keys when it reaches the limit, which is exactly what you want for a cache.

Limit how long keys live

Some code stores data in the cache without an expiry time. The Redis Object Cache plugin supports a WP_REDIS_MAXTTL constant that sets a maximum lifetime in seconds for every key, which keeps stale data from lingering indefinitely. A value of a day or a week works well for most sites.

Keep connections fast

Redis on the same server as PHP, connected through 127.0.0.1 or a Unix socket, gives the lowest latency. If Redis runs on a separate server, keep it in the same data centre, because every cache lookup crosses the network.

Using the Object Cache in Your Own Code

Developers get the most from a persistent cache by caching their own expensive work. The pattern is simple: try the cache, and only do the work when the value is missing.

function ak_get_popular_products() {
    $products = wp_cache_get( 'popular_products', 'ak' );

    if ( false === $products ) {
        $products = wc_get_products( array(
            'limit'   => 8,
            'orderby' => 'popularity',
            'return'  => 'ids',
        ) );
        wp_cache_set( 'popular_products', $products, 'ak', HOUR_IN_SECONDS );
    }

    return $products;
}

Without a persistent cache, this still saves repeated work within a request. With Redis, the result is shared across all requests for an hour. A few more tips:

  • Use a cache group, such as ak above, to keep your keys organised.
  • Load many keys at once with wp_cache_get_multiple() instead of looping over single lookups.
  • Clear what you changed. When the underlying data updates, call wp_cache_delete() for the affected key so visitors see fresh data.
  • Use transients when you need them to work without Redis too. They fall back to the database when no persistent cache exists, and move into Redis automatically when one is installed.

Custom block binding sources are a good example of code that benefits from this pattern, as I mention in my WordPress Block Bindings API guide.

Object Cache, Page Cache and Speculative Loading Together

It helps to think of caching in layers. A page cache delivers complete pages without running PHP. An object cache makes the requests that do run PHP faster. Speculative loading starts the next navigation early, so cached pages feel instant. Each layer covers a different part of the experience, and together they make a site feel quick for every kind of visitor. My guide to WordPress speculative loading explains that last layer in detail.

Background work benefits too. Cron tasks and queues load WordPress repeatedly, and each run becomes lighter when options and objects come from memory. If you are reviewing those tasks, my WordPress cron jobs guide is a natural next step, and store owners will find the WooCommerce HPOS migration guide useful for speeding up order data.

Troubleshooting Tips

Changes do not appear on the site

If data is changed directly in the database, for example during a migration or with a manual SQL query, the cache does not know about it. Run wp cache flush or use the flush button on the Redis settings screen. Changes made through WordPress itself clear the relevant keys automatically.

The site shows a connection error

Check that the Redis service is running and that the host, port and password in wp-config.php match. If you need the site back immediately while you investigate, wp redis disable removes the drop-in, and WordPress returns to its default in-memory cache.

Memory fills up quickly

Confirm the maxmemory and allkeys-lru settings, add a maximum TTL, and check which groups use the most space. Very large cached values often come from options that have grown over time, which a database review can tidy up.

Frequently Asked Questions

Is a Redis object cache the same as page caching?

No. Page caching stores finished HTML pages. An object cache stores the pieces of data WordPress uses to build pages. Most sites benefit from both.

Will it help my PageSpeed score?

It mainly improves server response time for uncached requests, which helps Time to First Byte and the overall experience for logged-in users and shoppers. Front-end scores also depend on images, CSS and JavaScript, which I cover in my guides on INP optimization and cutting load time.

Does PHP version matter?

Yes. A current PHP version and an up-to-date PHP Redis extension give the best results. My guide to the best PHP version for WordPress explains how to choose.

Keeping Your Redis Setup Secure

Redis is designed to run inside a trusted network, so a few simple precautions keep your cache private and reliable:

  • Keep Redis off the public internet. Bind it to 127.0.0.1 or a private network address, and make sure the firewall does not allow outside access to port 6379.
  • Use authentication. Set a strong password, or use access control lists on newer Redis versions, especially when Redis runs on a separate server.
  • Separate sites clearly. Give every WordPress site its own prefix or database number so data never overlaps.
  • Keep everything updated. Update the Redis server, the PHP extension and the WordPress plugin as part of your normal maintenance.

Redis Object Cache Setup Checklist

Use this list to confirm everything is in place after setup, or when reviewing a site someone else configured:

  1. Redis server running and reachable only from the web server.
  2. PHP Redis extension installed for the PHP version the site uses.
  3. Connection details and a unique prefix defined in wp-config.php.
  4. One object cache drop-in active, with wp redis status reporting a valid connection.
  5. maxmemory set, with the allkeys-lru eviction policy.
  6. A maximum key lifetime configured with WP_REDIS_MAXTTL.
  7. Hit ratio and database query counts checked after the cache has warmed up.

Once these points are covered, the object cache needs very little ongoing attention. A quick look at the hit ratio and memory use during your regular maintenance is usually all it takes to keep it running smoothly for years.

Conclusion

A WordPress Redis object cache is one of the most effective upgrades for any site with dynamic, logged-in or e-commerce traffic. It reduces database work, speeds up the dashboard and makes uncached pages respond faster. Confirm Redis is available, set a unique prefix, enable the drop-in, tune memory with an LRU policy, and check the hit ratio. With those steps in place, your site will make the most of the hosting you already pay for.

Images: photos by Winston Chen and Rick Rothenberg on Unsplash.

Leave a Reply

Your email address will not be published. Required fields are marked *