Performance8 min read

Magento 2 Varnish & CDN Caching: Setup That Sticks

Get Magento 2 full-page cache, Varnish, and CDN layers working together — cache keys, purge rules, and the mistakes that silently bypass FPC.

Illustration of Magento 2 Varnish and CDN caching layers

Full-Page Cache and Varnish Roles

Magento's FPC decides what is cacheable; Varnish stores and serves it. Installing Varnish without configuring Magento's VCL and backend host mapping leaves you with file FPC and disappointing TTFB.

Verify X-Magento-Cache-Debug headers on staging. HIT/MISS patterns tell you whether customer segments, currency, or custom cookies are fragmenting the cache unnecessarily.

Purge Rules and Cache Tags

Product and category saves must purge the right cache tags. Custom modules that write catalog data without dispatching clean events create classic 'stale price' bugs after merchandising updates.

On multi-node setups, ensure purge requests reach every Varnish instance. A load-balanced pair where only one node receives PURGE is a production incident waiting for peak traffic.

CDN in Front of Varnish

Put a CDN in front for static assets and, carefully, HTML if your provider supports Magento-aware purge. Never cache authenticated customer HTML at the CDN edge.

Separate static and HTML cache policies. Long-lived hashed static files plus short HTML TTL with origin shield usually outperforms trying to cache everything aggressively.

Need help with your Magento 2 project?

Talk to Our Team

Magento tips in your inbox

Practical Magento 2 guides, performance notes, and product updates from Magecube. Unsubscribe anytime.