Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Magento 2 Seminar - Toon van Dooren - Varnish in Magento 2

270 views

Published on

An overview by Toon van Dooren about how Varnish works in Magento 2

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Magento 2 Seminar - Toon van Dooren - Varnish in Magento 2

  1. 1. Varnish in Magento 2 By Toon Van Dooren
  2. 2. Varnish? Varnish Webserver MissHIT
  3. 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. 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. 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. 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. 7. Magento 2 functionalities - Purge to ban - Esi for shorter lifetimes - Ajax + local storage for hole punching - Content tagging - Segmentation - Caching static content
  8. 8. Purge to ban
  9. 9. ESI MagentoPageCacheControllerBlockEsi
  10. 10. Ajax + localstorage - Localstorage - mage-cache-storage - mage-cache-storage-section-invalidation - mage-cache-timeouts - Copies localstorage content to placeholder - Event -> ajax call -> localstorage -> copy - customer-data.js
  11. 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. 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. 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. 14. Questions? - Varnish? - Cache invalidation - Hole punching - Varnish in Magento 2 - Functionalities + Quick dive - Purge to ban - ESI - Ajax + local storage - Content tagging - Segmentation

×