Varnish Cache sits in front of your Magento web servers and serves cached HTML pages without touching PHP. A properly configured Varnish setup can handle 10,000+ requests per second from a single server, serving cached pages in under 5ms. Here's our production VCL configuration and the cache invalidation strategy that keeps content fresh.
Core VCL Configuration for Magento
Magento ships a default VCL that handles the basics. Customize it for: larger object size limits (Magento pages can be large), Grace mode to serve stale content during backend failures, and saint mode to route around unhealthy backends. Set a minimum TTL of 1 hour for cacheable pages — Magento's cache tags handle invalidation, so aggressive TTLs are safe.
ESI for Dynamic Content
Edge Side Includes (ESI) let you cache the full page while keeping specific blocks dynamic. The minicart (showing item count), customer greeting, and recently viewed products should be ESI blocks — loaded separately by Varnish after the main page is served from cache. This pattern is more complex than simple full-page cache but dramatically improves the cache hit rate for logged-in customers.
Cache Invalidation with X-Magento-Tags
Magento assigns cache tags to every cached page — tags that identify which products, categories, and CMS blocks are included. When a product is saved, Magento sends a BAN request to Varnish with the relevant tags. Varnish instantly invalidates all pages containing that product. This is why you can safely use long TTLs — stale content is invalidated on data change, not on timer expiry.