huguesalary / Magento-Varnish

This Magento extension provides a Real Full Page Caching for Magento powered by Varnish with support of Session-Based information caching (Cart, Customer Accounts, ...) via ESI includes
Other
95 stars 18 forks source link

[Enhancement] Prevent the administration area from being cached #9

Closed kdckrs closed 12 years ago

kdckrs commented 12 years ago

In the varnish configuration (vcl) file look for the following:

if(beresp.http.X-Magento-DoNotCache == "1")

and replace it by

if(beresp.http.X-Magento-DoNotCache == "1" || req.http.Cookie ~ "adminhtml")

This will make sure that there is no caching if you are logged in and have the adminhtml cookie.

huguesalary commented 12 years ago

Hi @KennyDs, The admin area is not cached. You can verify this fact by reading the layout file: app / design / adminhtml / default / default / layout / varnish.xml line 18

You will see:

<!-- We do not cache anything in the admin, change this setting at your risks... -->
<default>
    <!-- Seriously, do not change this... -->
    <varnish_do_not_cache></varnish_do_not_cache>
</default>

<varnish_do_not_cache></varnish_do_not_cache> indicates the Magento-Varnish extension to set the X-Magento-DoNotCache header to true. This header is intercepted by Varnish and thus, Varnish doesn't cache the administration area.

However, when you first install the extension, because Magento does not yet communicates with Varnish, the admin area gets cached. Did you correctly follow the last steps of the installation process?

Connect to your Magento administration area (most likely to be http://yourhost/admin) Go in System->Cache Management and disable every cache Go in System->Configuration->General->Varnish->Module Activation and set "Enable Varnish Module" to yes and click save

note: Once you set this to yes and save, you will certainly notice that "Enable Varnish Module" stayed set to no. That's normal! Don't spend hours trying to set it to yes, just go on to the next step.

Go back in System->Cache Management and click the "Flush Cache Storage" button.`

kdckrs commented 12 years ago

When you say:

note: Once you set this to yes and save, you will certainly notice that "Enable Varnish Module" stayed set to no. That's normal! Don't spend hours trying to set it to yes, just go on to the next step."

It isn't normal behaviour, and the suggestion I did above fixed this issue. Once you apply the suggestion I mentioned it will be set to "Yes". This will also make sure that nothing from the admin is cached when people are using a different suffix for the administration area. (other than /admin/)

huguesalary commented 12 years ago

@KennyDs, please re-read my previous comment. It is a normal behavior when you first install the extension, because Magento does not yet communicates with Varnish.

The admin area is not cached anymore once you clear all caches on the Magento Cache Management.

Even if the suffix of your admin area is not "admin".

Please, re-read my previous comment, it is clearly explained how the admin area is not cached.

I do not want to exclude the admin area in the Varnish VCL, because I want developers to be able to cache things in the admin area if they want to.

If you still don't understand, after installing the extension please do:

$varnishadm ban.url .

then

$cd rm -fR magento/install/path/var/cache/

if your magento cache is not on the filesystem (you are using either Redis, Memcached, DB, ...) do whatever is needed to clear this cache.

Once you have cleared all your caches you will notice that the admin area is not cached.

You can verify this fact by looking at the headers sent by Magento when you are in the admin area. They will look like that:

Set-Cookie:adminhtml=5tfjrg33jkn426i819vvrmf7k0; expires=Fri, 12-Oct-2012 01:14:13 GMT; path=/;     domain=.whatever.com; secure; httponly
Via:1.1 varnish
X-Magento-Donotcache:1
X-Powered-By:PHP/5.3.3-7+squeeze8
X-Varnish:1639025575
X-Varnish-Cache:MISS
X-Varnish-EsiLevel:0
X-Varnish-Frontend-Cookie:No Frontend Cookie
X-Varnish-Storage:1282.628 765.372 false
X-Varnish-Url:/index.php/admin/dashboard/index/key/679c9cd937c3626ac465ff06c76658ff/

Please note the X-Magento-Donotcache:1 and X-Varnish-Cache:MISS headers which indicates that Magento asked varnish to not put the response in cache, and that the request generated a "Cache MISS" meaning that the response has not been served from the cache, but fetched from the backend.