- What is object caching?A dynamic site builds each page by running code and asking the database many questions: the post, the menu, the settings, the…
- How does it differ from page caching?The two work together.
- When does object caching help?Shops and membership sites where many pages are personalised.
What is object caching?
A dynamic site builds each page by running code and asking the database many questions: the post, the menu, the settings, the user. Many of those answers are the same for every visitor and change rarely. Object caching keeps the results in fast memory, so the next request gets them without touching the database. Redis, an in-memory data store, is the common choice, and Memcached is another. WordPress has a built-in object cache API that, with a plugin and a Redis server, stores results persistently between requests.
How does it differ from page caching?
The two work together. Page caching handles the easy traffic, and object caching speeds up the requests that cannot be cached as whole pages, such as checkout and admin screens.
| Page caching | Object caching | |
|---|---|---|
| What is stored | The finished HTML page | Database query results and computed data |
| Best for | Anonymous visitors on public pages | Logged-in users, carts, dashboards and dynamic parts |
| Where it lives | Server, plugin or CDN | Redis or Memcached memory |
| Effect | Skips PHP and the database entirely | Makes PHP and database work cheaper |
| Risk | Showing stale pages | Stale data if invalidation is poor |
When does object caching help?
- Shops and membership sites where many pages are personalised.
- Sites with many plugins and database queries per page.
- Busy WordPress admin areas, search and filtering pages.
- Sites that already have page caching but still show a slow time to first byte on uncached requests; see what TTFB is.
What is Redis and how does it work with your site?
Redis stores data in memory and answers in fractions of a millisecond. The site software sends it a key, such as the cached result of a query, and Redis returns the value or says it has none. A plugin or the framework handles when to store and when to clear. Redis needs memory, so on small plans a cache of a few tens of megabytes is typical, and you should size it to your data. It can also persist data to disk, but for caching you can usually accept losing it on a restart.
How do you set it up?
- Check your host supports it
Look for Redis or Memcached on the plan, or ask support.
- Enable the service
On managed hosts it is a switch; on a VPS install and secure Redis yourself.
- Connect your application
In WordPress, use a persistent object cache plugin and add the connection details to the configuration.
- Test and monitor
Check hit rates, memory use and that logged-in pages still work.
What are the risks and limits?
- Stale data if keys are not cleared when content changes.
- Memory use: an undersized cache evicts data constantly and gives little benefit.
- Security: never expose Redis to the internet; bind it to the local address and use a password; see how to secure a new VPS.
- Compatibility issues with some plugins.
- A false sense of speed: it does not fix slow code or heavy pages.
How do you know if it is working?
Look at the cache hit rate, which Redis reports, and at the number of database queries per page before and after, using a query monitor plugin or logs. Compare the response time of an uncached request, such as a logged-in page, before and after. If the hit rate is low or memory keeps filling, adjust the size and the expiry. Keep a backup before you change configuration, and test on staging first.
What are the common mistakes?
- Installing a Redis plugin without a Redis server.
- Leaving Redis open to the internet.
- Using object caching to hide a slow plugin instead of fixing it.
- Setting the memory too small, or never expiring keys.
- Assuming it replaces page caching.
A worked example: a shop before and after object caching
A WooCommerce shop has page caching for catalogue pages, but each logged-in customer page and each cart request still runs 120 database queries and takes about 900 milliseconds on the server. The owner adds Redis with a persistent object cache plugin on their VPS. After a day of warming, the hit rate settles around 90 percent, queries per request fall to about 40 and the same cart request takes around 350 milliseconds. CPU use at peak drops, which lets the owner stay on the current plan for another year.
The numbers will differ on every site, but the pattern is typical: the biggest gain comes where requests cannot be served from a page cache. The owner then sets a memory limit for Redis and an eviction policy, so the cache cannot grow without bound.
What settings matter in Redis for caching?
- Maximum memory: set a limit sized to your working data.
- Eviction policy: choose one that removes the least recently used keys when memory is full.
- Key expiry: give cached items a sensible lifetime so stale data does not linger.
- Authentication and network binding: require a password and listen only on the local address.
- Persistence: usually unnecessary for a cache; restart means a short warm-up.