Skip to main content

WordPress Caching Strategy: Redis & Page Cache

Implement a multi-layer WordPress caching strategy with Redis object cache, full-page caching, fragment caching, and cache invalidation rules.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
You are a WordPress performance engineer. Help me implement a comprehensive caching strategy for a high-traffic news publication WordPress site serving 500,000 monthly visitors.

Step 1: Set up Redis as the persistent object cache. Install and configure Redis Object Cache by Till Kruss to connect WordPress to the Redis server at 127.0.0.1:6379. Configure the Redis connection: database index 0, key prefix wp_prod_ (to support multiple sites on the same Redis instance), connection timeout of 1 second, and maximum memory of 512 MB with the allkeys-lru eviction policy. Verify the connection by checking the Redis info output and the WordPress Site Health object cache status.

Step 2: Implement full-page caching using WP Super Cache. Configure page cache rules: cache all public pages with a TTL of 12 hours, exclude logged-in users (serve dynamic pages), exclude cart, checkout, my-account, wp-admin from caching, exclude pages with specific cookies (woocommerce_cart_hash, wordpress_logged_in_*), and exclude POST requests. Set up cache preloading that crawls the sitemap after cache purge to warm the cache. Configure the cache storage backend to use file-based (for Nginx fastcgi_cache compatibility).

Step 3: Implement fragment caching for dynamic sections within cached pages. Identify 5 page fragments that change frequently but do not require a full page purge: trending posts sidebar, live comment count, stock status badges, user greeting, breaking news ticker. Use the Transients API with Redis backend to cache each fragment independently. Set per-fragment TTLs ranging from 5 minutes for frequently changing content to 1 hour for semi-static content. Use AJAX or Edge Side Includes (ESI) to inject dynamic fragments into cached pages.

Step 4: Design cache invalidation rules. Map content change events to cache purge actions: new post published (purge homepage, archive pages, related category pages), post updated (purge single post, listing pages), comment added (purge single post), plugin settings changed (purge all), theme customizer saved (purge all), WooCommerce product stock changed (purge product page and shop page). Implement smart purging that only invalidates affected URLs, not the entire cache.

Step 5: Configure browser-level and CDN caching. Set Cache-Control headers: 1 year for static assets (CSS, JS, images), no-cache for HTML pages (handled by server-side page cache), and immutable for versioned assets. Configure Cloudflare CDN with pull-zone settings, custom cache keys, and purge API integration. Set up Surrogate-Control headers for CDN-specific TTLs that differ from browser TTLs.

Step 6: Build a cache monitoring and debugging system. Install Query Monitor plugin + Redis CLI monitoring to track: object cache hit ratio (target 90%), page cache hit ratio, Redis memory usage and eviction rate, page load time with and without cache, and cache purge frequency. Create a WP-CLI command that reports cache health: wp cache-health report. Set up alerts when the hit ratio drops below 75% or Redis memory exceeds 80%. Add a cache debug mode (activated by a query parameter in local and staging only) that shows cache status in response headers.

What this prompt does

This prompt makes the model a WordPress performance engineer designing a multi-layer caching strategy for a [site_type] serving [monthly_visitors] monthly visitors. It works through six layers: Redis object cache, full-page cache, fragment caching, invalidation rules, browser/CDN caching, and monitoring.

Object caching connects WordPress to Redis via [redis_plugin] with [redis_memory] under an LRU policy and a [key_prefix] so multiple sites can share one instance. Page caching uses [page_cache_plugin] with a [page_cache_ttl] TTL, excluding logged-in users, [excluded_pages], and [excluded_cookies]. Fragment caching covers [fragment_count] dynamic sections ([dynamic_fragments]) on their own TTLs. The invalidation map is the centerpiece: it purges only affected URLs on each content event rather than nuking everything.

The layering matters because each tier handles what the others cannot. Full-page caching serves complete HTML to anonymous visitors at a [page_cache_ttl] TTL, fragment caching keeps frequently changing sections fresh without a full purge, and Redis object caching accelerates the dynamic pages that can never be fully cached. Browser and [cdn_provider] CDN headers push static assets out to the edge with long lifetimes, while HTML stays under server control. The monitoring layer ties it together, tracking hit ratios toward [hit_ratio_target], Redis memory and eviction rate, and alerting when things slip, so the strategy stays measurable rather than hopeful.

When to use it

  • A high-traffic site needs layered caching, not a single plugin toggle.
  • You want Redis as a persistent object cache via [redis_plugin].
  • Full-page caching must exclude carts, checkouts, and logged-in users.
  • Parts of a page change often but should not trigger a full purge.
  • You need precise invalidation so content updates appear without dumping the whole cache.
  • You want hit-ratio monitoring against [hit_ratio_target] with alerts.

Example output

Expect a layered implementation plan: Redis object-cache config via [redis_plugin] with [key_prefix] and [redis_memory], full-page rules in [page_cache_plugin] at [page_cache_ttl] excluding [excluded_pages] and [excluded_cookies], fragment caching for [dynamic_fragments] with TTLs from [min_fragment_ttl] to [max_fragment_ttl], an event-to-purge invalidation map, browser and [cdn_provider] CDN headers, and a monitoring setup tracking hit ratio toward [hit_ratio_target] with alerts below [alert_threshold].

Pro tips

  • Set [redis_memory] with an allkeys-lru policy so the cache evicts gracefully instead of erroring under pressure.
  • Always exclude [excluded_pages] and [excluded_cookies] from page cache, or logged-in and cart states will leak.
  • Use a [key_prefix] if Redis is shared, so sites do not collide on keys.
  • Map each content event to the minimum set of URLs to purge; whole-cache flushes tank your [hit_ratio_target].
  • Tune fragment TTLs between [min_fragment_ttl] and [max_fragment_ttl] per fragment rather than using one global value.
  • Watch eviction rate alongside hit ratio; a high eviction rate means [redis_memory] is too small, not that caching failed.
  • Preload the cache from the sitemap after a purge so the first visitor does not pay the cold-cache cost on a [monthly_visitors]-scale site.
  • Gate the cache-debug query parameter to [dev_environments] only, so production responses never leak cache internals in their headers.

Frequently Asked Questions

Why use both Redis and a full-page cache instead of just one?
They solve different problems. The full-page cache via `[page_cache_plugin]` serves complete HTML to anonymous visitors fast, while Redis object caching via `[redis_plugin]` speeds up the dynamic pages that cannot be fully cached, such as logged-in and cart views.
How does it avoid serving cached pages to logged-in users?
The page cache rules exclude logged-in users, `[excluded_pages]` like cart and checkout, and requests carrying `[excluded_cookies]`. POST requests are bypassed too, so dynamic and personalized states are always served fresh.
What makes the cache invalidation smart rather than blunt?
Instead of flushing everything on any change, the prompt maps each event to specific purges, for example a new post clears the homepage and related archives only. This targeted invalidation keeps the hit ratio near `[hit_ratio_target]` while still showing fresh content.
How do I know the caching is actually working?
The monitoring layer tracks object and page cache hit ratios, Redis memory and eviction rate, and load times with and without cache. It alerts when the hit ratio drops below `[alert_threshold]` or memory exceeds `[memory_alert_threshold]`, and adds a `wp cache-health report` command.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in WordPress & CMS Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support