Send the link below via email or IMCopy
Present to your audienceStart remote presentation
- Invited audience members will follow you as you navigate and present
- People invited to a presentation do not need a Prezi account
- This link expires 10 minutes after you close the presentation
- A maximum of 30 users can follow your presentation
- Learn more about this feature in our knowledge base article
Do you really want to delete this prezi?
Neither you, nor the coeditors you shared it with will be able to recover it again.
Make your likes visible on Facebook?
Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.
Varnish Cache and its usage in the real world
Transcript of Varnish Cache and its usage in the real world
and its usage in the real world
What is Varnish?
Started in Magento Core Team in 2007
Fan of Test Driven Development
CTO at Interactiv4
Trainer at MageCampus
Varnish is an HTTP accelerator designed for content-heavy dynamic web sites.
There is nothing in cache
There is a cached version of page
Varnish is all about VCL*
* Varnish Configuration Language
no ttl hit_for_pass
ttl is set
And this flow is
But we are not going to use all of these VCL subs...
Control the access to admin or cache refresh
Detect a customer segment based on cookies
Remove redundant query parameters and cookies:
Newsletter Campaign parameters
Detect SSL offload, an external load balancer, etc
Building cache hash for page
Gives possibility to serve different content based on:
Customer device type (tablet, mobile, desktop)
Detected Customer Segment
SSL Offload parameters, etc
Processes response headers from Magento backend
The entry point for a customer request
Check if request has to be cached
Removes redundant headers for a cached content
Sets appropriate flags for processing ESI tags
Supply additional response headers
The last point where you can modify response that is send to client
Used to set cookies, depending on customer segment
Here you can hide headers from end client, that are used only for communications between Varnish and Magento backend
The secret of successful Magento Varnish integration is in 4 key components
1. HTTP Headers
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Specify cache TTL from Magento
Specify object ids, that are present on the page
Segmentation of request based on detected country or device
Make smart rules for ESI processing
Connect dynamic actions to a cached segment: store code, customer group
Store a dynamic action hash, for triggering dynamic block update on the page
4. Browser Storage
Cache dynamic blocks with customer related data, retrieved by AJAX calls
Making AJAX calls for retrieving dynamic page parts
Set Cookies on Dymanic Actions from static pages
For all of these I developed a framework...
Varnish Chef Cookbook
Magento Varnish Integration
Sample Vagrant Configuration
By default it caches such pages:
Category View + Layered Navigation
But adding a new page type is very simple...
Add a page to the list of known handles
Layout handle that is used for your custom page
Label, that will appear in Magento Configuration
Specify default TTL for this page
Layout handle + _time suffix
TTL value in seconds
So you will need to make some very small adjustments to your theme.
1. Find your dynamic block on the page
2. Find appropriate cookie for it
3. Specify your dynamic block via
Custom Layout XML
But what if you need to add some custom object into varnish?
It doesn't make your cached website dynamic by default, because every theme is different.
By default it purges cache for such objects:
1. Create a Collector
2. Create a Processor
3. Register them in config.xml
Collects objects from a block where it is rendered
Processes collected objects and returns list of object tags
// Your logic to retrieve objects
Available Dynamic Cookies
– checksum of the current quote contents
– checksum based on the customer identification, if logged in customer gets changed
– boolean flag of the logged in state of the visitor
– checksum of the current customer segment:
customer group id
There is also some events available for you
When dynamic cookies are being updated:
When customer segment gets generated
But that is not all...
Additionally to extension you also get an awesome chef coookbook for configuring of your Varnish instance!