Tutorials

WordPress Object Cache with Redis; Step-by-Step Setup

A practical guide to WordPress object caching with Redis; what gets cached, how much speed you gain, and how to enable it on shared hosting.

Tutorials

What is WordPress object cache and why your site needs it

Your WordPress site runs dozens of queries against the MySQL database to display each page. Each query takes a few milliseconds, and when 50 visitors arrive at the same time, the database chokes. The result? TTFB above 2 seconds and the "Error establishing a database connection" error.

WordPress object cache is exactly where it steps in. Instead of WordPress reading settings, options, and repeated queries from the database every time, it keeps the result in memory. Next time, it gets the answer from memory. Simple. But the difference is striking.

My test on a staging site with 20 active plugins: without cache, each request took 420 milliseconds to respond. With Redis object cache, that number dropped to 98 milliseconds. More than 4 times faster. Where do you see this number? In tools like GTmetrix or ServerNet's free tools that show server response time separately from browser load time.

What exactly does Redis cache

Many people think object cache means caching the entire HTML page. That's wrong. Object cache works at a lower layer and stores these things:

  • Options from the wp_options table — where site settings, plugins, and theme are stored
  • Repeated database queries whose results don't change within a short time period
  • PHP objects like sessions and temporary plugin data
  • Output of heavy functions like wp_nav_menu or get_sidebar that get rebuilt from scratch every time

Important note: object cache is different from page cache. Page cache like W3 Total Cache or WP Super Cache stores the final HTML output. Object cache works underneath it and helps WordPress build the page faster. If you have page cache, add object cache too. These two are complementary, not replacements.

Redis or Memcached?

Both are free and popular options. But Redis wins. Why? Because it also stores data on disk (persistence), and if the service restarts, the cache isn't lost. Memcached keeps everything in RAM, and with one restart, everything is wiped. For high-traffic sites, this difference means a few minutes of heavy load on the database after every restart.

Redis also has a richer data structure: lists, sets, hashes. WordPress cache plugins like Redis Object Cache use these features. My choice is Redis. If your host only offers Memcached, it's better than nothing, but if you have a choice, go with Redis.

Setting up WordPress object cache with Redis on shared hosting

On shared hosting, you don't have root access and can't install Redis. So you have to use the Redis that the hosting provider has set up. First, check whether Redis is even enabled on your host. Create a PHP file with this content and run it:

<?php
$redis = new Redis();
try {
    $redis->connect('127.0.0.1', 6379);
    echo 'Connected: ' . $redis->ping();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
?>

If you see "Connected: +PONG" as output, Redis is active. If you get a Connection refused error, there are two possibilities: Redis isn't installed, or it's on a different port and address. On shared hosting, some companies serve Redis on a Unix socket or a non-standard port. Ask the hosting support for the exact address.

This is where people make mistakes: many install and activate the Redis Object Cache plugin but forget to "enable" the cache from the plugin settings page. The plugin gets installed, but the cache doesn't work. The site stays slow, and they think Redis is useless. After installing the plugin, be sure to go to Settings → Redis and click the Enable Object Cache button. If you don't see this button, it means the plugin couldn't connect to Redis.

Step-by-step installation and configuration

  1. From the WordPress dashboard, install and activate the Redis Object Cache plugin. This plugin is free and has over 600,000 active installations.
  2. Go to Settings → Redis. If the connection is established, you'll see the "Connected" status.
  3. Click the Enable Object Cache button.
  4. To be sure, test the cache: open your site once, then refresh the plugin settings page. The Hit Count counter should go up.

If your host doesn't allow installing specific plugins or you encounter the "Predis\Connection\ConnectionException" error, there's probably a password set for Redis that the plugin doesn't know. Add this line to your wp-config.php file:

define('WP_REDIS_PASSWORD', 'your_redis_password');

And if the port is non-standard:

define('WP_REDIS_PORT', 6380);

How much difference does it make? Real numbers

Let's be honest. Object cache doesn't work miracles. If your site has poor coding or heavy images, object cache only solves part of the problem. But for standard WordPress sites, here are my numbers:

ScenarioWithout object cacheWith Redis object cache
Number of database queries40 to 805 to 15
TTFB (time to first byte)400 to 700 milliseconds80 to 150 milliseconds
Server CPU usageHighLow

These figures were obtained on regular shared hosting, not a dedicated server. Important point: object cache reduces the number of queries, not the time of each query. If your database itself is slow (for example, on an old HDD), object cache helps, but it doesn't fix the root cause.

Another note: if your site has very low traffic (for example, 100 visits per day), object cache won't make a noticeable difference. Because cache is valuable when there are many repeated requests. For low-traffic sites, first enable page cache, then move on to object cache.

Common problems and solutions

WordPress object cache isn't without its headaches. These are things I've seen actually happen:

"Connection refused" error

This means the plugin can't connect to Redis. First check whether Redis is enabled on your host. On shared hosting, some companies only enable Redis for specific plans. If your plan doesn't include Redis, you'll need to upgrade or use a file-based object cache.

Cache stays stale and changes aren't applied

This problem occurs when plugins or your theme use functions that WordPress doesn't know should clear the cache. For example, a visit statistics plugin that stores the number every time in options. Solution: In Redis Object Cache settings, click the "Flush Cache" option, or use the wp_cache_flush() function in your theme's functions.php file.

Conflict with page cache

Some page cache plugins like W3 Total Cache have their own built-in object cache. If you enable both the page cache plugin with Redis option and install Redis Object Cache, you'll have two cache layers stacked on top of each other, wasting memory. Choose one: either use W3 Total Cache's built-in object cache, or use separate Redis Object Cache. Not both.

Object cache on shared hosting; limitations

On shared hosting, Redis is usually shared between multiple users. That means Redis memory is limited, and your site might only get 32 or 64 megabytes of it. If your site is large and the cache keeps filling up, the Hit Rate might drop and the cache becomes ineffective.

How do you find out? In the Redis Object Cache settings page, look at the statistics. If the Hit Rate is below 70%, it means your cache is too small or data expires too quickly. In this case, you can enable caching only for important options or migrate to Linux hosting with dedicated resources. Make this decision based on numbers, not feelings.

Another limitation: some shared hosts run Redis on the same server where your site is hosted. If another user on the same server overloads Redis with heavy queries, your site will slow down too. This is the risk of shared hosting, and there's no definitive solution except migrating to a more dedicated environment.

When to disable object cache

Yes, there are cases where object cache becomes troublesome. If your site uses WooCommerce with real-time inventory and customers sometimes see incorrect stock counts, object cache is probably holding product data that hasn't been updated in time. WooCommerce usually manages the cache, but third-party plugins might not work correctly.

If you see such an error, first flush the cache. If the problem repeats, disable cache for that specific page. In Redis Object Cache, you can use the wp_cache_set function with the expire=0 parameter to disable cache for specific data. But if the entire site has problems, turn off object cache and find the root cause in the plugin.

My choice? For 90% of WordPress sites, I enable object cache with Redis. For heavy e-commerce sites with real-time transactions, I test first, and if I see conflicts, I disable it for specific pages. This is a tool, not magic. You need to understand its behavior.

Frequently asked questions

What's the difference between WordPress object cache and page cache?

Page cache stores the final HTML output and sends it directly to the browser. Object cache keeps intermediate data like options and queries in memory so WordPress can build the page faster. These two are complementary, and both can be enabled simultaneously.

Does Redis object cache work on all shared hosts?

No. Redis must be installed and enabled on the server. Some hosts only have Memcached, and some have neither. Before installing the plugin, contact hosting support or check with the PHP test script provided in this article.

How much does object cache speed up a site?

In my tests, TTFB went from about 500 milliseconds to 100 milliseconds, meaning roughly 4 times faster. But this number depends on the number of plugins, code quality, and database size. Light sites will see less difference.

After enabling object cache, site changes aren't visible. How do I clear the cache?

From the Settings → Redis page in the WordPress dashboard, click the Flush Cache button. If you don't have access to the dashboard, run wp_cache_flush from phpMyAdmin, or delete the object-cache.php file from the wp-content folder to disable the cache.

ServerNet Support

ServerNet engineering & editorial team — specialists in infrastructure, networking and web hosting.

WordPress Hosting
Share:

Comments 0

No comments yet — be the first!

Leave a comment

Related service

WordPress Hosting

A purpose-built WordPress stack on LiteSpeed Enterprise and NVMe — auto-install, secure updates, staging and caching that keeps you on top of Google.