---
title: Object Caching
description: Set up a persistent object cache in WordPress with Powered Cache. Choose Redis, Memcached, Memcache or APCu, connect to your server and flush it safely.
url: "https://poweredcache.com/docs/object-caching/"
updated: "2026-12-02"
category: Caching
---

# Object Caching

An object cache keeps the results of database queries and other expensive work in memory, so WordPress does not repeat that work on every request. A persistent object cache keeps this data between requests in Redis, Memcached or APCu. It speeds up the requests that page caching cannot help with, such as the admin area, carts, checkouts and logged-in visits.

**Available in:** Powered Cache (free)
**Where to find it:** Powered Cache → Cache
**Requires:** the Redis, Memcached, Memcache or APCu PHP extension on your server, and for Redis and Memcached a running cache server.

## How object caching works

When you choose a backend and save, Powered Cache writes the `wp-content/object-cache.php` drop-in. WordPress loads this file on every request. It loads the matching object cache drop-in that ships with Powered Cache, so the plugin's own files stay the source of the code.

- When you change the backend, Powered Cache flushes the object cache.
- When you set Object Cache to **Off**, Powered Cache deletes `object-cache.php`, but only if it created that file.
- While [Development Mode](/docs/development-mode/) is on, the object cache drop-in is removed. It comes back when you turn Development Mode off.

## Which backends you can choose

The **Object Cache** select only lists backends whose PHP extension is loaded on your server. If none is found, the only option is **Off**, and the setting reads *No supported persistent object cache PHP extension was detected on this server.*

| Option | PHP extension it needs | Where data is stored | Default connection |
| --- | --- | --- | --- |
| **Redis** | PhpRedis (`redis`) | A Redis server | `127.0.0.1:6379`, database 0 |
| **Memcached** | `memcached` | One or more Memcached servers | `127.0.0.1:11211` |
| **Memcache** | `memcache` (the older extension) | One or more Memcached servers | `127.0.0.1:11211` |
| **Apcu** | `apcu` | Shared memory of PHP on the same server | No server needed |

The list only checks the PHP extension. It does not check that a Redis or Memcached server is running and reachable. Ask your host which backend they support and for its connection details. If your host offers Redis, it is a good choice for most sites. APCu suits small sites on a single server.

> **Changed in 4.0:** The Object Cache select only shows backends that your PHP installation supports. Before 4.0, every backend was listed, even when it could not work on the server.

## Enable object caching

1. If your cache server does not use the default address, add its connection details to `wp-config.php` first. See the section for your backend below.
2. Go to **Powered Cache → Cache**.
3. Choose a backend in **Object Cache**.
4. Click **Save Settings**.
5. Go to **Powered Cache → Advisor** and find the **Object cache** check. It should show **Ready** and say, for example, *Redis object cache is configured.* See [Optimization Advisor](/docs/optimization-advisor/).

When you choose **Memcache** or **Memcached**, the settings screen checks the size of your autoloaded options. WordPress loads these options on every request and stores them as a single item in the object cache. Memcached handles very large items poorly, so you see a warning above about 700 KB and an error above about 900 KB. Clean up unused options, for example with [Database Cleanup](/docs/database-cleanup/) or by removing old plugins, before you turn on a Memcached backend.

## Connection settings for each backend

Connection details are not settings in the Powered Cache screen. You set them in `wp-config.php`, above the line `/* That's all, stop editing! */`. If you use the default address, you do not need to add anything.

### Redis

Set the `$redis_server` variable. All keys are optional except `host`:

```
$redis_server = array(
    'host'     => '127.0.0.1',
    'port'     => 6379,
    'auth'     => 'your-redis-password',
    'database' => 0,
);
```

- To connect through a Unix socket, set `host` to the socket path, for example `/var/run/redis/redis.sock`. The port is then ignored.
- If `$redis_server` is not set and your host provides the `CACHE_HOST`, `CACHE_PORT`, `CACHE_PASSWORD` and `CACHE_DB` server variables, Powered Cache uses them automatically.
- Flushing the object cache empties the whole Redis database that the site uses. If several sites or applications share one Redis server, give each one its own `database` number.
- If WordPress cannot connect, administrators see a notice such as *Warning! WP Redis object cache cannot connect to Redis server.* Check the host, port and password.

### Memcached

Set the `$memcached_servers` variable to one or more `host:port` entries:

```
$memcached_servers = array(
    'default' => array(
        '127.0.0.1:11211',
    ),
);
```

Add more entries to the inner list to spread the cache over several Memcached servers.

### Memcache

This option uses the older `memcache` PHP extension to talk to the same kind of Memcached server. It reads the same `$memcached_servers` variable as the Memcached option. It also accepts Unix sockets in the form `unix:///path/to/memcached.sock`. Choose it only when your host provides the `memcache` extension and not `memcached`.

### APCu

APCu (shown as **Apcu** in the select) stores the cache in PHP's own shared memory, so there is no server to configure. Keep in mind:

- The cache lives on one server only. If your site runs on several web servers, each one has its own copy, so use Redis or Memcached instead.
- The available memory is limited by the APCu settings of your PHP installation.
- Cache keys include the path of your WordPress installation and the `WP_APCU_KEY_SALT` constant (default `wp`), so two installations on the same server do not mix data.

### Several sites on one cache server

Powered Cache sets `WP_CACHE_KEY_SALT` to your database name unless you define it yourself. This keeps the data of two sites apart when they share one Redis or Memcached server. If two sites use the same database name, for example on different servers, define a unique value for each:

```
define( 'WP_CACHE_KEY_SALT', 'shop-example-com' );
```

## Flush the object cache

While a backend is selected, the admin bar shows **Powered Cache → Purge Object Cache**. It empties the object cache and leaves your cached pages alone. **Purge All Cache** flushes the object cache too. See [Clear Cache](/docs/clear-cache/).

You rarely need to flush by hand. Flush when data looks out of date after you change the database directly, import content, or restore a backup.

## Multisite

There is only one `object-cache.php` for the whole network, so the object cache always affects every site. For that reason:

- Powered Cache writes `object-cache.php` only when the plugin is network-activated and a network administrator saves the settings. With per-site activation, the selected backend is saved but no drop-in is written.
- **Purge Object Cache** and **Purge All Cache** are shown only to network administrators.

See [Multisite Setup](/docs/multisite-setup/).

## If another plugin already uses object-cache.php

WordPress supports only one object cache drop-in. Plugins such as Redis Object Cache, and some hosts, install their own `object-cache.php`.

- If you choose a backend in Powered Cache, it **replaces** the existing `object-cache.php` with its own.
- If you leave Object Cache set to **Off**, Powered Cache never touches a drop-in that another plugin or your host installed.

Use one object cache solution only. If your host manages the object cache, or you prefer another plugin for it, keep Object Cache set to **Off**. If you want Powered Cache to manage it, deactivate the other object cache plugin first, then choose a backend in Powered Cache.

## Troubleshooting

### "The object cache file seems missing"

A backend is selected, but `wp-content/object-cache.php` does not exist. This happens when `wp-content` is not writable, or another plugin removed the file. Click **Fix configuration** in the notice, or in the **Regenerate Configuration** card in Powered Cache → Tools. See [Fix Configuration](/docs/fix-configuration/).

### "The object cache file couldn't be loaded"

The drop-in exists, but it cannot find the backend file inside the Powered Cache plugin folder. This can happen after the plugin folder was moved or renamed. Click **Fix configuration** in Powered Cache → Tools (**Regenerate Configuration** card) to write the drop-in again.

### The site is slower or shows errors after enabling it

Set Object Cache back to **Off** and save. Then check with your host that the cache server is running and that your connection details are correct. If you use Memcache or Memcached, check the size of your autoloaded options as described above.

## For developers

- `POWERED_CACHE_OBJECT_CACHE_DROPIN`: the full path of a custom object cache drop-in that `object-cache.php` loads instead of the bundled one.
- Redis options: `WP_REDIS_USE_RELAY` connects through the Relay extension instead of PhpRedis, and `WP_REDIS_DEFAULT_EXPIRE_SECONDS` sets a default expiry for items stored without one (default `0`, no expiry).
- Filters: `powered_cache_object_cache_dropins` changes the list of backends and their drop-in files, and `powered_cache_object_cache_file_content` changes the generated `object-cache.php`. See the [hook reference](https://poweredcache.github.io/docs/).

## Related docs

- [Page Caching](/docs/page-caching/)
- [Clear Cache](/docs/clear-cache/)
- [Fix Configuration](/docs/fix-configuration/)
- [wp-config Constants](/docs/wp-config-constants/)
- [Hosting Compatibility](/docs/hosting-compatibility/)
