- Object caching keeps database query results in memory and reuses them across requests, not only within one.
- It helps most where page caching cannot: logged-in users, carts, checkouts and the admin area.
- Redis is the right default. Memcached works but has fewer WordPress features and loses everything on a restart.
- Without a persistent object cache, WordPress rebuilds the same query results on every request.
- Set
maxmemory-policy allkeys-lruon Redis, or a full cache starts refusing writes instead of dropping old keys.
What does object caching do for WordPress?
It keeps the results of database queries in memory so the next request can reuse them. WordPress already has an object cache, but by default it only lasts for a single request. A persistent backend such as Redis keeps it between requests, so a query that ran once can answer many visitors.
| Default WordPress | With Redis | |
|---|---|---|
| Cache lifetime | One request | Until the data changes or expires |
| Same query on the next request | Runs again against the database | Read from memory |
| Helps logged-in users | No | Yes |
| Helps the admin area | No | Yes |
| Helps WooCommerce checkout | No | Yes |
The last three rows are the point: a full-page cache cannot help with any of those pages.
It does not replace page caching
Page caching stores finished pages for visitors who are not logged in, and is the bigger win on a content site. Object caching stores query results and helps everywhere, including pages that can never be cached whole. Busy sites want both. See setting up an Nginx reverse proxy cache.
When will object caching actually help?
The gain depends on how much of your traffic cannot be page cached, and how many queries your pages run. A small brochure site behind a page cache will barely notice. A shop where every visitor has a session will notice a lot.
| Site type | Expected benefit | Why |
|---|---|---|
| Brochure site, mostly anonymous | Small | Page caching already answers nearly every request |
| Busy blog with comments | Moderate | Logged-in commenters bypass the page cache |
| WooCommerce shop | Large | Carts and checkout are never page cached |
| Membership or LMS site | Large | Almost every visitor is logged in |
| Site with a very large options table | Large | Autoloaded options are read on every request |
| Multisite network | Large | Site and network options are queried constantly |
If most of your traffic is logged out and already cached, spend the effort elsewhere first.
cd /var/www/example.com
# Queries per page load: over 100 suggests real headroom
wp eval 'global $wpdb; get_posts(); echo $wpdb->num_queries . " queries" . PHP_EOL;'
# Autoloaded options: over 1 MB and object caching will help a lot
wp db query "SELECT ROUND(SUM(LENGTH(option_value))/1024/1024, 2) AS mb
FROM wp_options WHERE autoload='yes'"
# Is a persistent object cache already active?
wp cache typeRedis or Memcached: which should I use?
Use Redis, unless your setup already standardises on Memcached. Both are fast enough that speed does not decide it. Redis has better tooling, more data types, optional persistence (saving to disk) and a better-maintained WordPress plugin.
| Redis | Memcached | |
|---|---|---|
| Speed for WordPress | Fast | Fast: no meaningful difference |
| Survives a restart | Yes, optionally | No, cache is lost |
| Data types | Strings, hashes, lists, sets | Strings only |
| Grouped cache invalidation | Yes | Limited |
| WordPress plugin | Redis Object Cache, actively maintained | Older, less active |
| Also usable for | Sessions, queues, rate limiting | Caching only |
Restarts matter more than they sound: a Memcached restart empties the cache and sends every request to the database at once.
# 1. Redis server and the PHP extension
sudo apt install -y redis-server php8.3-redis
sudo systemctl enable --now redis-server
# 2. Confirm PHP can see it
php -m | grep redis
redis-cli ping # expect PONG
# 3. Enable it in WordPress
cd /var/www/example.com
wp plugin install redis-cache --activate
wp redis enable
wp redis statuswp redis status says Connected, it is live.# /etc/redis/redis.conf
# Localhost only. Redis has no authentication by default.
bind 127.0.0.1 ::1
protected-mode yes
# Cap the memory Redis may use
maxmemory 512mb
# Evict the least recently used keys when full. This line is essential.
maxmemory-policy allkeys-lru
# A cache does not need disk persistence; skip the write overhead
save ""
appendonly no
sudo systemctl restart redis-serverNever expose Redis to the internet
Redis has no password by default. Anyone who finds an internet-facing instance can read and write it, and attackers have used that to plant SSH keys on servers. Bind it to localhost, or use a private network and a password.
How do I confirm the object cache is working?
cd /var/www/example.com
# Should report 'redis', not 'default'
wp cache type
# Plugin's own view: connection status, hit ratio, keys stored
wp redis status
# Live Redis statistics
redis-cli info stats | grep -E 'keyspace_hits|keyspace_misses'
redis-cli info memory | grep -E 'used_memory_human|maxmemory_human'
redis-cli dbsize
# Watch commands in real time (development only, it is noisy)
redis-cli monitor# Queries per request, with the cache on and off
wp eval 'global $wpdb; get_posts(["posts_per_page"=>20]); echo $wpdb->num_queries . PHP_EOL;'
wp redis disable
# run it again, note the number
wp redis enable
# Time to first byte on a page that bypasses the page cache
for i in $(seq 1 10); do
curl -s -o /dev/null -w '%{time_starttransfer}\n' \
"https://example.com/my-account/?nocache=$RANDOM"
done | awk '{s+=$1} END {printf "avg %.3fs\n", s/10}'| Symptom | Cause | Fix |
|---|---|---|
| wp cache type says default | The drop-in is missing | wp redis enable, and check wp-content is writable |
| Connection refused | Redis is not running or is on another port | systemctl status redis-server; redis-cli ping |
| Hit rate stays very low | Cache is being flushed constantly | A plugin is calling wp_cache_flush on every request |
| OOM command not allowed | Redis is full with noeviction set | Set maxmemory-policy allkeys-lru |
| Stale content after an edit | A plugin is not invalidating its own keys | Flush with wp cache flush, then report it |
Row four is the one that takes a site down, and a one-line configuration change prevents it.
How do I use object caching safely on WooCommerce?
WooCommerce gains more than most sites, because carts, accounts and checkout can never be page cached. It also has the most to lose from a caching mistake, so follow these rules exactly.
- Never page cache the cart, checkout or account pages. Object caching is safe there; full-page caching is how customers end up seeing each other's baskets.
- Give Redis enough memory for your catalogue, or a large shop keeps dropping useful keys and the hit rate stays low.
- Test stock levels under load after you enable it. Stale stock is the failure that costs money, and it only shows with many shoppers at once.
- Flush the cache when you deploy, so old cached values cannot outlive the code that wrote them.
- Keep watching the hit rate. A plugin added later that flushes the cache on every request quietly undoes the gain.
# Flush the WordPress object cache
wp cache flush
# On a Redis shared with other sites, give each site its own prefix and
# selective flush in wp-config.php, so wp cache flush only clears its keys:
# define('WP_REDIS_PREFIX', 'example_com:');
# define('WP_REDIS_SELECTIVE_FLUSH', true);
# Nuclear: empties EVERY database on the instance.
# Never run this on a Redis shared with other sites or services.
redis-cli FLUSHALLwp cache flush clears the whole Redis database, and FLUSHALL clears every site's cache at once.Your hosting should provide this layer
On G7Cloud each WordPress site has its own Redis inside its own container, at 127.0.0.1:6379, so a neighbour's traffic cannot push out your keys. We offer Redis rather than Memcached. See our WordPress caching and WooCommerce speed optimisation.
If the database itself is the problem rather than the number of queries, caching only hides it. Safely trimming a large WordPress or WooCommerce database deals with the size problem underneath.
Frequently asked questions
What is object caching in WordPress?
Keeping the results of database queries in memory so later requests reuse them instead of querying again. By default WordPress only does this within a single request. A persistent backend such as Redis keeps the cache between requests, which is where the gain comes from.
Do I need object caching if I already have page caching?
If nearly every visitor is anonymous and served from the page cache, the extra gain is small. If visitors log in, as on a shop or membership site, object caching helps exactly the pages page caching cannot.
Is Redis or Memcached better for WordPress?
Redis for most sites. Speed is similar, but Redis offers optional persistence, more data types, better cache invalidation and a better-maintained WordPress plugin. Choose Memcached only if your setup already standardises on it.
How much memory should I give Redis?
256 MB is enough for a typical content site; 512 MB to 1 GB suits a busy WooCommerce shop with a large catalogue. Watch used_memory_human against maxmemory_human and raise it if keys are often evicted. Always set maxmemory-policy to allkeys-lru.
Is object caching safe for WooCommerce?
Yes, and it helps a lot, because carts and checkout can never be page cached. Keep full-page caching off cart, checkout and account pages, and test stock behaviour under load after enabling it.
Why is my Redis hit rate so low?
Usually something flushes the cache constantly, often a plugin calling wp_cache_flush on every request, or the cache is too small and keys are evicted before they are reused. Check redis-cli info stats for evicted_keys, and raise maxmemory if that number keeps climbing.
About G7Cloud Engineering
Articles written by the engineers who build and run G7Cloud: UK managed hosting and the AI Website Builder. We write about what we operate every day: containers, backups, databases, and the small-business websites that run on them.
More about G7Cloud →