How Do Cloudflare, WP Rocket and Redis Work Together?

How do Cloudflare, WP Rocket, Redis and OPcache work together on the same WordPress site? Layers, exclusions, purge order, server settings and common mistakes.
Technical summary
Technology
Cloudflare, WP Rocket, Redis, OPcache
Topic
WordPress cache architecture
Level
Intermediate
In this article7 sections

Most speed problems on WordPress sites come not from a lack of caching but from cache layers working without knowing about each other. Cloudflare stores one thing, WP Rocket another, Redis a third; nobody has defined which one is purged when content is updated. The result: either a site that shows old pages or a cache that shows a logged-in user’s cart to another visitor. Below we explain how OPcache, Redis, WP Rocket (full-page cache) and Cloudflare work together on the same site, what each layer does and the mistakes we see most often in the field.

The path a request takes

  1. Cloudflare (edge): The data center closest to the visitor receives the request. Static files (CSS, JS, images) and, if a rule is defined, HTML that’s in the cache are served without going to the server at all.
  2. Full-page cache (WP Rocket or server cache): When the request reaches the server, if a ready-made HTML file exists it’s served directly; PHP and the database don’t run.
  3. PHP + OPcache: If the page isn’t in the cache, WordPress runs. Because OPcache keeps PHP files compiled in memory, code isn’t recompiled on every request.
  4. Redis (object cache): WordPress’s repeated query and computation results (options, menus, transients) are read from memory; the number of queries sent to the database drops.
  5. MariaDB/MySQL: Data that isn’t in the cache is read from the database.

This order is also the order to follow when troubleshooting. For a slowness complaint, first find out at which layer the request was answered. If a request that gets a HIT at the edge is slow, the problem isn’t on the server. If a request that bypasses the full-page cache is slow, the place to look is PHP and the database.

What each layer does, and its limits

Layer What it speeds up When it has no effect
Cloudflare Static files, HTML via rules; geographic latency Session-based and personalized pages
Full-page cache Anonymous visitor pages Logged-in users, cart, checkout, form results
OPcache All PHP execution Constant recompilation with wrong memory settings
Redis Admin panel, WooCommerce, uncached pages The slow query itself (if its result can’t be cached)

The distinction in the table says this: each layer speeds up a different type of traffic, and none replaces another. On a corporate site with mostly anonymous visitors, full-page cache and Cloudflare carry most of the load. In a WooCommerce store, since cart and checkout pages can’t be cached, the share of Redis and OPcache grows.

What needs tuning at the server layer

For OPcache, the opcache.memory_consumption and opcache.max_accelerated_files values are set according to the total number of PHP files on the server. On a multi-site server (a separate WordPress core, theme and dozens of plugins for each site), the default values fill up quickly and OPcache starts recompiling constantly. Cache fill level and restart count are monitored in the opcache_get_status() output.

For Redis, maxmemory must be defined, and for cache use an eviction policy such as allkeys-lru is chosen as the maxmemory-policy. Without a limit, Redis consumes the server’s memory; with a limit but a noeviction policy, writes fail when memory fills up. If several sites share the same Redis instance, each site gets its own key prefix (e.g. WP_REDIS_PREFIX in the Redis Object Cache plugin) or a separate database number. Without a prefix, sites can read each other’s options.

Extra performance can be gained in OPcache by disabling opcache.validate_timestamps; but then file changes aren’t visible until PHP-FPM is reloaded. On a WordPress site where plugin and theme updates are done from the panel, this setting becomes the source of “I updated it but nothing changed” complaints. If it’s disabled, a PHP-FPM reload step is added to the deployment process. On sites updated from the panel, leaving it enabled and keeping opcache.revalidate_freq reasonable is the safer choice.

The right exclusions

Most caching errors come from wrong exclusions. The following requests should not be cached in the full-page cache or Cloudflare:

  • /wp-admin/, wp-login.php, preview links and the personalized endpoints of the REST API.
  • Requests carrying the WordPress session cookie (wordpress_logged_in_*) or WooCommerce cookies (woocommerce_items_in_cart, wp_woocommerce_session_*).
  • Cart, checkout and my account pages; form submission results.
  • Pages personalized by query string (tracking parameters can be excluded).

Exclusions must be the same on both layers. If the cart page is excluded in WP Rocket but Cloudflare caches all HTML, the plugin’s exclusion means nothing. The request is answered at the edge before it reaches the server.

For WooCommerce-specific problems and a test method, see the WooCommerce cache errors guide.

The purge chain

When a post is updated, the purge order should be from the inside out: first the related keys in the object cache, then the related page and archives in the full-page cache, and finally the same URLs in Cloudflare. If the order runs in reverse, Cloudflare empties, the first visitor gets the old HTML from the server and the edge stores that old copy again. That’s the site that looks purged but shows old content.

The official WP Rocket–Cloudflare integration or API-based purging automates this chain. Deleting the entire cache on every change may look simple, but under heavy traffic it puts a sudden load on the server: hundreds of pages whose cache was emptied fall through to PHP at the same time. URL-based purging is preferred over bulk purging, and if needed a crawl that re-warms the cache (preload).

Common mistakes

  • Two full-page cache plugins active at the same time, or both a plugin and a server cache.
  • A “Cache Everything” rule enabled in Cloudflare without a session cookie exclusion.
  • Redis memory limit and eviction policy not set; errors when memory fills up.
  • OPcache memory and file count limits too small; constant recompilation on multi-site servers.
  • CSS/JS combining and deferral settings enabled without testing; interaction or layout broken.

The last item needs extra attention. When WP Rocket’s JavaScript delay feature and Cloudflare’s Rocket Loader are both enabled, scripts are reordered twice; menus, forms and the cookie banner can stop working. A single tool should manage JavaScript loading. The same principle applies to HTML minification and image optimization.

Verification

After setup, response headers should be checked: cf-cache-status (HIT/MISS/BYPASS) for Cloudflare, and the header or HTML comment the plugin adds for the page cache. From the command line, check quickly with curl -sI https://domain/ | grep -i cf-cache-status; send the same request twice and see whether the second returns a HIT. Test separately with a logged-in user, a browser with a product in the cart and an anonymous browser.

On the Redis side, the plugin’s status screen or the Redis Object Cache plugin’s WP-CLI command wp redis status shows the connection and that the drop-in file (object-cache.php) is active. On the server, the keyspace_hits and keyspace_misses values in the redis-cli info stats output give the hit rate; if the hit rate is low, either the memory limit is too small or keys are constantly being invalidated. A situation often seen in the field is the drop-in file staying in place even though the Redis service has stopped. Depending on the plugin and version, the site either throws an error or quietly runs without a cache; that’s why the Redis service is included in monitoring too.

Uncached response time should also be measured. A cache hides a slow application but doesn’t fix it. If a request that bypasses the cache takes 3 seconds, the admin panel, the cart and the first visitor after every cache purge experience those 3 seconds. For the server side, see the PHP-FPM and MariaDB guide.

Frequently asked questions

Do Redis and WP Rocket do the same job?

No. WP Rocket stores the ready-made HTML page so PHP doesn’t run at all. Redis, on the other hand, keeps the results of repeated database queries in memory when PHP does run (logged-in users, the cart, the admin panel, uncached pages). They complement each other.

If Cloudflare caches HTML, how are updates reflected?

When content is updated, the related URLs must also be purged in Cloudflare. This is automated with the Cloudflare plugin, the WP Rocket integration or the API; otherwise visitors see the old page until the cache expires.

Can we use two page cache plugins together?

Not recommended. Two full-page caches break each other’s files and headers, and the purge logic gets muddled. Each layer should have a single responsible tool.

To set up your site’s cache layers together, see our WordPress cache and CDN optimization service.

Support

Contact us for support or a discovery session on this topic.

Contact form
[email protected]

Eretek Web

We build and maintain corporate websites, WordPress and CMS platforms, intranet and SharePoint portals, document management, and form and approval workflows, and keep them secure and up to date.

Knowledge Center

Other articles