1

I have installed varnish in my centos server.

But varnish age is always 0, my guess is it will be 0 because Magento serves content from it's cache or it blocks others to cache.

I can see there are loads of extension available.

However, I want to understand what's going on and how can I achieve this without installing any third party extension.

6

You can try using Nexcess_Turpentine, a free and community maintained Varnish and Magento module.

From the module README.md

Features

Full Page Caching, with hole-punching via Varnish ESI and/or AJAX, even for logged in visitors
Configurable via standard Magento methods (Admin system configuration and layout XML), no manual editing of Varnish config required for most cases
Able to generate and apply new Varnish VCLs (configurations) on the fly, without restarting/changing Varnish's config files or flushing the cache
Blacklist requests from caching by URL or parameters (SID, store, etc)
Configure cache TTL by URL and individual block's TTL
Supports multiple Varnish instances for clustered usage
Automatic cache clearing on actions (clearing product/catalog/cms page after saving)
Supports non-root Magento installs (i.e. putting Magento in /store/ instead of /) and multi-store/multi-site setups
Support for site-crawlers for cache warming, and includes a (basic) built-in site-crawler
SSL support through Pound or Nginx

Disclamer: I work for Nexcess and help maintaining the module.

  • took this much of time to prepare this ??? !!! :) – Rajeev K Tomy Jul 22 '15 at 12:51
  • I have to sleep a couple of hours a day! – mbalparda Jul 22 '15 at 12:52
  • and you have a valid point. +1 for your sleep :) – Rajeev K Tomy Jul 22 '15 at 12:53
1

The way to make this work without installing a plugin involves understanding how your Magento application is put together.

There are 2 components that make up your Magento site:

  1. Static content - This could be images, CSS, JS or even generic HTML documents
  2. Dynamic/Personalised content - This is content that changes for each user - eg. The number of items in someones cart. This is something that cannot be shared amongst multiple users

You need a strategy to let Varnish cache all static content (including generic HTML pages) and then load dynamic content another way.

Varnish implementation options:

There are 2 main methods of implementing HTML document caching:

  1. Loading personalised elements of the page via additional requests after the page has loaded. A common implementation method here is to use AJAX to request page elements that are personalised. This means that the HTML document itself becomes cacheable across the board and lightweight AJAX calls fetch the personalised information.
  2. Varnish supports a technology called ESI (Edge Side Includes) that allows different parts of a HTML document to be cached differently.

Disclaimer - we run cloud Varnish instances with full metrics/logs for Magento at www.section.io but for Magento specifically we do recommend the Nexcess Turpentine module as the work involved in removing personalised to Ajax calls can be indepth and Turpentine is a quick win.

In good news, Magento 2 supports Varnish out of the box as its preferred caching solution so all of the hard work has been done to load personalised content via AJAX!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.