VVimal Roy

WordPress Database and Caching for High-Traffic Sites

Vimal Roy
Vimal RoyPublished Updated
WordPress Database and Caching for High-Traffic Sites

A page cache solves the easy problem: serving the same rendered HTML to anonymous visitors without touching PHP or MySQL at all. Everything else still hits the database. Every cache miss, every logged-in request and every dynamic fragment runs WordPress's actual queries. That layer mattered most on Coin Edition as it grew from 10K to 700K monthly visitors, and page cache alone stopped being enough well before that ceiling.

Why is WordPress still slow with a page cache enabled?

Because without a persistent object cache, WordPress's internal cache resets on every request. wp_cache_get() and wp_cache_set() are still called, but nothing persists between page loads, so the same expensive queries run again and again. Adding Redis or Memcached as the object cache backend turns that into a real cache: repeated queries, transients and term and meta lookups are served from memory instead of round-tripping to MySQL.

// Transients automatically use the persistent object cache
// when one is configured. No extra code is required, but it's
// worth confirming with an explicit check during setup:
if ( wp_using_ext_object_cache() ) {
    error_log( 'Persistent object cache is active' );
}

On a site that's already page-cached but still slow for logged-in editors, WooCommerce carts or any request the page cache can't serve, this is usually the single biggest improvement available.

Audit autoloaded options in wp_options

The wp_options table has an autoload column, and every row with autoload = 'yes' is loaded into memory on every request, including requests that never touch that data. Plugins are the usual culprit, quietly autoloading megabytes of settings, transients that were never excluded, or serialized arrays that grow without limit.

Query wp_options for autoload = 'yes' rows sorted by size every so often, and look into anything unexpectedly large. Store transients with set_transient() and an expiration where you can: transients saved that way aren't autoloaded, while a plugin writing them through raw add_option() calls is a common source of bloat. Deactivating a plugin doesn't always clean up its options either, so a periodic audit also catches orphaned rows from tools removed months ago.

Meta queries don't scale linearly

WP_Query with several meta_query clauses is convenient, and at scale it's one of the most common sources of slow admin screens and archive pages. Each clause is effectively a JOIN against wp_postmeta, where meta_value isn't indexed. For data that's queried constantly and needs to scale, a custom table with proper indexes will outperform stacked meta queries, at the cost of some of the convenience of the native WordPress APIs.

Reach for a custom table when a field is queried or sorted on often and at volume, not for every custom field. Where meta_query can't be avoided, keep it to a single clause where possible and test the query against realistic data. Put index-heavy custom tables behind a small data-access layer so the rest of the theme doesn't need to know the difference.

How do the cache layers fit together?

Page cache sits in front, object cache underneath, and a database schema that avoids expensive joins for common queries at the bottom. Each layer covers what the one above it misses. The middle layer is the one most often skipped: a site that's fast for anonymous visitors and slow for everyone else almost always has no persistent object cache.

What I changed on Coin Edition

I set up a Redis object cache with Relay and cached the data every request needs, so it's fetched quickly instead of rebuilt each time. I added other cache layers, found the slow queries and fixed them, and removed autoloaded options nobody needed.

Triage order

If you're triaging a slow, page-cached site, check in this order: whether a persistent object cache is active, how large the autoloaded options are, and which meta queries run on the slowest screens.

Vimal Roy

Written by Vimal Roy

Senior Web Developer based in Dubai, UAE, with 9+ years building and scaling WordPress, ReactJS, and Next.js platforms.

Drafted with AI assistance. Vimal reviewed and edited it, and the results come from his own project work.