All posts

Blog

Redis Object Cache for WordPress: What It Is and When You Need It

Illustrated cover for the Speed & Performance guide "Redis Object Cache for WordPress: What It Is and When You Need It"

Page caching gets most of the attention in WordPress speed guides, and for good reason. But there is a whole category of pages it can't help with: the WooCommerce cart, the checkout, a member's account page, the WordPress dashboard itself. Those pages are built fresh for every request, and they often hammer the database with the same queries again and again.

That is the gap Redis object cache fills. This guide explains what it does, when it makes a real difference, and how to set it up without breaking anything.

What is an object cache?

Every time WordPress builds a page, it asks the database for things: site options, menus, post data, user data, plugin settings, product details. Many of those queries return identical results request after request.

WordPress already has a built-in object cache, but by default it only lasts for a single page load. Once the request finishes, everything is thrown away and the next visitor starts from zero.

A persistent object cache keeps those results around between requests. WordPress checks the cache first, and only goes to MySQL when the data isn't there. That means fewer database queries, less waiting, and less load on the server.

What is Redis?

Redis is an open-source, in-memory data store. Because it keeps data in RAM rather than on disk, reads and writes are extremely fast. It is widely used for caching, sessions and queues across all kinds of applications, not just WordPress.

For WordPress, Redis acts as the storage backend for that persistent object cache. A small drop-in file (object-cache.php in wp-content) tells WordPress to send cache reads and writes to Redis instead of discarding them.

Memcached is an older alternative that does a similar job. Either works; Redis is more common in WordPress setups today and supports more data types and features.

When Redis helps, and when it doesn't

Redis is not a universal speed button. Its value depends on how much of your traffic is uncached and database-heavy.

Sites that usually benefit

  • WooCommerce stores, especially the cart, checkout and account pages
  • Membership and LMS sites where most visitors are logged in
  • Forums and community sites built on bbPress or BuddyPress
  • Sites with a slow wp-admin, particularly with many plugins or large product catalogs
  • Sites that rely on transients heavily (plugins storing temporary data)

Sites that may see little difference

  • A small blog or brochure site with good page caching, where nearly every visitor gets a cached HTML page that never touches PHP or the database
  • Very low-traffic sites where the database is never under pressure

If you are unsure, measure before and after (more on that below) rather than assuming.

Requirements before you start

To use Redis object cache you need three pieces:

  1. A Redis server running and reachable from your site. On a VPS you can install it yourself. On shared hosting it is only available if your host provides it.
  2. The PHP Redis extension (phpredis) or a PHP library such as Predis, so PHP can talk to Redis.
  3. A WordPress plugin that installs the object cache drop-in. Popular choices include "Redis Object Cache" by Till Krüss, and LiteSpeed Cache, which has object cache settings built in for LiteSpeed servers.

If your host doesn't offer Redis on shared hosting, don't try to work around it. Ask them, or consider whether you need it at all.

Setting it up on a VPS (overview)

On a typical Ubuntu or Debian VPS the general steps look like this:

  1. Install Redis from your distribution's packages, for example sudo apt install redis-server.
  2. Make sure Redis only listens on localhost (bind 127.0.0.1 ::1 in redis.conf) so it isn't exposed to the internet. Redis exposed publicly without a password is a well-known security risk.
  3. Set a memory limit and eviction policy in redis.conf, for example maxmemory 256mb and maxmemory-policy allkeys-lru, so Redis drops the least-recently-used keys instead of growing without limit.
  4. Install the PHP Redis extension for your PHP version and restart PHP-FPM or your web server.
  5. Install your chosen WordPress plugin and enable the object cache from its settings screen.

If several WordPress sites share one Redis instance, give each site its own key prefix or database number. Most plugins let you set WP_REDIS_PREFIX or a similar constant in wp-config.php. Without it, sites can read each other's cached data, which causes very confusing bugs.

Setting it up on shared hosting

On shared hosting that supports Redis, the process is usually:

  1. Find Redis or "object cache" in your control panel, or ask support for connection details.
  2. Install the cache plugin your host recommends.
  3. Enter the host, port or socket path, and any password provided.
  4. Enable the object cache and check the plugin's status screen shows "Connected."

How to tell whether it is working

Don't just switch it on and hope. Check:

  • The plugin status page. It should show connected, with hits and misses.
  • Hit ratio. After the site has been running for a while, a healthy cache serves most lookups from Redis. A very low hit ratio means something is off.
  • Query Monitor. This free plugin shows how many database queries a page runs. Compare an uncached page (like the cart) with Redis off and on.
  • Real-world timing. Time a few dynamic pages and wp-admin screens before and after. Our guide on how to test website speed covers tools for this.

Common problems and fixes

Changes don't appear. If you edit data directly in the database (bypassing WordPress), the cache doesn't know. Flush the object cache from the plugin.

The site breaks after Redis stops. A good drop-in falls back to the database if Redis is unavailable, but some configurations don't. If your site goes down when Redis does, check the plugin settings or remove wp-content/object-cache.php to disable it quickly.

Memory fills up. Without a maxmemory limit, Redis can grow until the server runs low on RAM. Always set a limit and an eviction policy.

Stale data across sites. Set a unique prefix per site, as covered above.

Redis vs page caching: you want both

Think of them as partners. Page caching serves complete HTML to anonymous visitors and skips WordPress entirely. Object caching speeds up the requests that can't be page-cached. A store with both configured feels fast for browsers and buyers alike. Our overview of types of website caching shows how the layers stack.

Wrapping up

Redis object cache is one of the most effective upgrades for dynamic WordPress sites, especially WooCommerce and membership sites where page caching can't help much. Make sure Redis is private, memory-limited and prefixed per site, measure the before and after, and you will know for sure whether it is pulling its weight.