magento 2 seminar - toon van dooren - varnish in magento 2

Post on 21-Jan-2017

74 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Varnish in Magento 2

By Toon Van Dooren

Varnish?

Varnish Webserver

MissHIT

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

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

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)

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

Magento 2 functionalities

- Purge to ban- Esi for shorter lifetimes- Ajax + local storage for hole punching- Content tagging- Segmentation- Caching static content

Purge to ban

ESI

Magento\PageCache\Controller\Block\Esi

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

Content tagging- X-Magento-Tags

- Data object name + id

- Object models extend IdentityInterface- Magento\Framework\DataObject\IdentityInterface- getIdentities returns a string with tags

- Abstractblock adds tags- Magento\Framework\View\Element\AbstractBlock

- Purgecache model purges tags on object save- Magento\CacheInvalidate\Model\PurgeCache

Segmentation- X-Magento-Vary- Plugin around http context dispatch

- Magento\Framework\App\Http\Context- 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

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)

Questions?- Varnish?

- Cache invalidation- Hole punching

- Varnish in Magento 2- Functionalities + Quick dive

- Purge to ban- ESI- Ajax + local storage- Content tagging- Segmentation

top related