Permalink
Browse files

Bypass cache when item is added to be compared #5

Thanks wbdv for the patch.
Updates varnish config to not cache wishlist.
  • Loading branch information...
1 parent 1092d9a commit eb3df7f575fad572f2cc379bfa73cc2b4617215b @madalinoprea committed Jun 4, 2011
Showing with 13 additions and 11 deletions.
  1. +6 −0 code/Varnish/Helper/Cacheable.php
  2. +3 −7 code/Varnish/Model/Observer.php
  3. +4 −4 varnish.vcl
@@ -42,6 +42,12 @@ public function quoteHasItems()
return $quote instanceof Mage_Sales_Model_Quote && $quote->hasItems();
}
+ public function hasCompareItems()
+ {
+ // see Mage_Catalog_Helper_Product_Compare
+ return Mage::helper('catalog/product_compare')->getItemCount() > 0;
+ }
+
public function isCustomerLoggedIn()
{
$customerSession = Mage::getSingleton('customer/session');
@@ -11,7 +11,6 @@ class Magneto_Varnish_Model_Observer {
public function varnish(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
- $response = $observer->getResponse();
$helper = Mage::helper('varnish/cacheable'); /* @var $helper Magneto_Varnish_Model_Cacheable */
// Cache disabled in Admin / System / Cache Management
@@ -29,18 +28,15 @@ public function varnish(Varien_Event_Observer $observer)
return false;
}
- if ($helper->quoteHasItems()) {
+
+ if ($helper->quoteHasItems() || $helper->isCustomerLoggedIn() || $helper->hasCompareItems()) {
$helper->turnOffVarnishCache();
+
return false;
} else {
$helper->turnOnVarnishCache();
}
- if ($helper->isCustomerLoggedIn()) {
- $helper->turnOffVarnishCache();
- return false;
- }
-
$helper->turnOnVarnishCache();
}
View
@@ -54,7 +54,7 @@ sub vcl_recv {
return (pass);
}
- # parse accept encoding rulesets to normalize0
+ # parse accept encoding rulesets to normalize
if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
@@ -76,12 +76,12 @@ sub vcl_recv {
# Don't cache pages for Magento Admin
# FIXME: change this rule if you use custom url in admin
- if (req.url ~ "^/admin" || req.url ~ "^/index.php/admin") {
+ if (req.url ~ "^/(index.php/)?admin") {
return(pass);
}
- # Don't cache checkout/customer pages
- if (req.url ~ "^/checkout" || req.url ~ "^/customer") {
+ # Don't cache checkout/customer pages, product compare
+ if (req.url ~ "^/(index.php/)?(checkout|customer|catalog/product_compare|wishlist)") {
return(pass);
}

0 comments on commit eb3df7f

Please sign in to comment.