3. Cache invalidation
Ban Purge
Intelligent cache invalidation Direct invalidation
Cache object exists until it is fetched from
backend
Instant object removal from cache
Exists until older than the oldest cache
object
Does not stay in memory
Everything that is known to Varnish (URLs,
IPs, Headers, …)
URLs
4. Cache invalidation
- Content tagging
- Object Identifiers in header
- X-Magento-Tags: catalog_product_14
- Ban specific objects
- ban obj.http.X-Magento-Tags ~ “catalog_product_14”
- Useful for
- Objects that can exist in multiple pages
- Paginated and sorted content
- Search pages
5. Hole punching
Esi Ajax
Has impact on pageload Async
Processed by Varnish + Webserver Processed by browser + web server
Private or public User specific (private)
Usage: crucial elements (navigation) Usage: independent elements (top cart)
6. Hole punching
- Avoid permanent hole punches
- Events: add to cart, login, …
- Leverage local storage or lifetimes combined
with bans
- Avoid unnecessary hole punches
- Does this content need to be invalidated?
- Local storage: https://github.com/toonvd/magento-localstorage-recentlyviewed
7. Magento 2 functionalities
- Purge to ban
- Esi for shorter lifetimes
- Ajax + local storage for hole punching
- Content tagging
- Segmentation
- Caching static content
11. Content tagging
- X-Magento-Tags
- Data object name + id
- Object models extend IdentityInterface
- MagentoFrameworkDataObjectIdentityInterface
- getIdentities returns a string with tags
- Abstractblock adds tags
- MagentoFrameworkViewElementAbstractBlock
- Purgecache model purges tags on object save
- MagentoCacheInvalidateModelPurgeCache
12. Segmentation
- X-Magento-Vary
- Plugin around http context dispatch
- MagentoFrameworkAppHttpContext
- Set value to add it to the header
- Context class hashes all set values
- HTTP class adds the vary header
- Vary header is added to Varnish hash
13. Before you begin
- Varnish is not the holy grail of performance
- Optimize your backend first!
- Do not use Varnish to hide bad coding
- Learn how to read / use Varnish Configuration Language
- Know your subroutines
- Know how to utilize them
- Personalise your VCL based on your needs
- Composing your VCL is not a sysadmin task!
- Decide whether you will cache static content
- Do you have enough RAM?
- Globalization needed? (Content Delivery Network)
14. Questions?
- Varnish?
- Cache invalidation
- Hole punching
- Varnish in Magento 2
- Functionalities + Quick dive
- Purge to ban
- ESI
- Ajax + local storage
- Content tagging
- Segmentation