Features Pricing Reviews FAQ
Get Plugin

Setting Up Object Cache (Redis and Memcached)

6 min read

A persistent object cache stores the results of database queries in memory, so WordPress repeats less work on every request. This guide shows you how to configure a Redis or Memcached backend in xSpeed Cache.

What this does

WordPress builds many small results from the database on each page load. Without a persistent object cache, those results are thrown away at the end of the request and built again on the next one.

An object cache keeps them in a fast in-memory store such as Redis or Memcached. The next request reads from memory instead of rebuilding the same data. This helps dynamic pages and logged-in traffic, which the page cache does not cover.

In xSpeed Cache, the Object Cache panel lets you:

  • See whether a persistent object cache drop-in is currently active and which backend it appears to be.
  • Save your backend connection settings.
  • Test the connection before committing to it.
  • Enable or disable the object cache, or copy a wp-config.php snippet to set it up by hand.
  • Flush the object cache.

Why use it

  • Repeated database results are read from memory instead of being rebuilt.
  • Helps dynamic and logged-in requests, which page cache does not serve.
  • Useful when you already run Redis or Memcached on your server.

Requirements

You need a Redis or Memcached server that WordPress can reach. xSpeed Cache connects using the PHP Redis or Memcached extension when it is available, and falls back to a built-in client if not.

How to set it up

  1. Go to the xSpeed Cache dashboard in your WordPress admin.
  2. Open the Object Cache panel.
  3. Choose a Backend: Redis or Memcached.
  4. Fill in the connection settings for that backend.
  5. Use Test connection to confirm xSpeed Cache can reach the server.
  6. Once the test passes, enable the object cache.

When you enable it, xSpeed Cache tests the connection again, writes its configuration into wp-config.php, and installs its object cache drop-in. If wp-config.php cannot be written, xSpeed Cache installs the drop-in and shows you the snippet to add by hand.

Note: xSpeed Cache will not write anything until the connection test passes. A failed test stops the enable step, so a misconfigured server cannot be turned on.

Settings explained

SettingWhat it doesDefault
BackendWhich cache server you intend to use. Affects the generated snippet.Redis
Redis HostHostname or IP of the Redis server.127.0.0.1
Redis PortPort for Redis.6379
Redis PasswordPassword for Redis, if it requires auth.Empty
Redis DatabaseRedis logical database number (0–15).0
Memcached HostHostname or IP of the Memcached server.127.0.0.1
Memcached PortPort for Memcached.11211
Cache Key PrefixA unique salt for this site’s cache keys.Empty
Connection Timeout (seconds)How long to wait for a connection (0–60).1
Persistent ConnectionsReuse the connection across PHP requests when supported.On

Backend

Chooses which cache server you plan to use, Redis or Memcached. This decides which connection fields apply and what the generated snippet contains. Default is Redis.

Redis connection settings

Used when Backend is Redis:

  • Redis Host — hostname or IP of the Redis server. Use 127.0.0.1 when Redis runs on the same machine as PHP. Default is 127.0.0.1.
  • Redis Port — the default Redis port is 6379.
  • Redis Password — leave blank if your Redis server runs without auth.
  • Redis Database — the logical database number, from 0 to 15. Use a dedicated database per site if Redis is shared. Default is 0.

Memcached connection settings

Used when Backend is Memcached:

  • Memcached Host — hostname or IP of the Memcached server. Default is 127.0.0.1.
  • Memcached Port — the default Memcached port is 11211.

Cache Key Prefix

A unique salt added to this site’s cache keys. Default is empty.

Set this when more than one WordPress site shares the same Redis or Memcached server. A unique prefix per site keeps their cache entries separate, so one site cannot read or overwrite another’s.

Connection Timeout (seconds)

How long xSpeed Cache waits for a connection to the cache server, from 0 to 60 seconds. Default is 1.

Keep this low, around 1 to 2 seconds. A short timeout means a misconfigured or unreachable cache server cannot stall your pages.

Persistent Connections

When on, the connection to the cache server is reused across PHP requests where supported. Default is on. This is usually faster. Turn it off only if your cache server complains about idle connections.

Testing and flushing

  • Test connection runs a live check against the backend using the values on screen, including unsaved ones. It reports success or failure with a short message, so you can confirm the settings before enabling.
  • Flush clears the object cache. It works against whatever object cache drop-in is active, or the default WordPress cache if none is installed.

The wp-config.php snippet

If you prefer to set things up by hand, or wp-config.php is not writable, xSpeed Cache generates a snippet you can paste yourself. The snippet uses the widely-used constant names, so it also works with common drop-ins such as Redis Object Cache.

For Redis, the snippet defines constants like WP_REDIS_HOST, WP_REDIS_PORT, WP_REDIS_DATABASE, WP_REDIS_TIMEOUT, and WP_REDIS_PERSISTENT. It adds WP_REDIS_PASSWORD only when you set a password, and WP_CACHE_KEY_SALT only when you set a Cache Key Prefix.

For Memcached, the snippet sets the $memcached_servers array with your host and port, plus WP_CACHE_KEY_SALT if you set a prefix.

Paste the snippet above the line in wp-config.php that says “That’s all, stop editing!”.

Important: A Cache Key Prefix is only included in the snippet when you actually set one. If you run several sites on one cache server, set a unique prefix on each so their caches stay separate.

Best practices

  • Always run Test connection before enabling, so you do not turn on a backend that cannot be reached.
  • Keep the Connection Timeout low so a cache problem never slows down your pages.
  • Set a unique Cache Key Prefix on every site that shares a cache server.
  • On a shared Redis server, give each site its own Redis Database number where you can.

Troubleshooting

  • The connection test fails. Check the host, port, and password. The test message names the backend and what went wrong, for example that the server did not respond or that authentication failed.
  • Enable did not finish. xSpeed Cache will not enable the cache if the connection test fails. Fix the connection first, then enable again.
  • wp-config.php is not writable. xSpeed Cache still installs the drop-in but cannot write the constants. Add the snippet shown on the panel to wp-config.php by hand.
  • A different drop-in is already installed. xSpeed Cache backs up a foreign object-cache.php before replacing it, so your previous drop-in is saved.

FAQ

Does enabling write to my wp-config.php? Yes. When you enable the object cache and wp-config.php is writable, xSpeed Cache writes its configuration between its own markers. Disabling removes that block again.

What happens when I disable it? xSpeed Cache removes its drop-in and strips its configuration block from wp-config.php.

Does Flush work if I use a different object cache plugin? Yes. Flush clears whichever object cache is active, regardless of which drop-in is installed.

  • How to Enable Page Cache
  • Configuring the Cache Preloader
  • Browser Cache Settings