diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php index 77e4ec675..4eb803d5f 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -139,6 +139,27 @@ protected function _getCustomIncludeFilename($position='') { } + /** + * Get custom cookie keys and add to varnish hash + * + * @return string + */ + protected function _getCustomCookieHash() { + $keys = Mage::getStoreConfig('turpentine_vcl/cookie/keys'); + if(!empty($keys)){ + $tpl = ''; + $keys = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, $keys); + foreach($keys as $key){ + $tpl .= 'if (req.http.Cookie ~ "'.$key.'=") {'.PHP_EOL; + $tpl .= 'hash_data(regsub(req.http.Cookie, "^.*?'.$key.'=([^;]*);*.*$", "\1"));'.PHP_EOL; + $tpl .= '}'.PHP_EOL; + } + return $tpl; + } + return null; + } + + /** * Get the custom VCL template, if it exists * Returns 'null' if the file doesn't exist @@ -1009,6 +1030,7 @@ protected function _getTemplateVars() { $this->_getVclTemplateFilename(self::VCL_CUSTOM_C_CODE_FILE) ), 'esi_private_ttl' => Mage::helper('turpentine/esi') ->getDefaultEsiTtl(), + 'custom_cookie_hash' => $this->_getCustomCookieHash(), ); if ((bool) Mage::getStoreConfig('turpentine_vcl/urls/bypass_cache_store_url')) { diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 575a425fd..a22b378e6 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -579,6 +579,25 @@ + + + text + 35 + 1 + 0 + 0 + + + + textarea + List of cookie keys to include in caching hash key. + 10 + 1 + 0 + 0 + + + text diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index 2223bedbc..97fbcb42c 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -288,6 +288,8 @@ sub vcl_hash { set req.hash += regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1"); } + {{custom_cookie_hash}} + return (hash); } diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index b960df79a..f39bb7767 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -291,6 +291,8 @@ sub vcl_hash { hash_data(regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1")); } + {{custom_cookie_hash}} + return (hash); } diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index efef43060..0d784c9dd 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -318,6 +318,9 @@ sub vcl_hash { req.http.Cookie ~ "customer_group=") { hash_data(regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1")); } + + {{custom_cookie_hash}} + std.log("vcl_hash end return lookup"); return (lookup); }