Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')) {
Expand Down
19 changes: 19 additions & 0 deletions app/code/community/Nexcessnet/Turpentine/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,25 @@
</bypass_cache_store_url>
</fields>
</urls>
<cookie translate="label" module="turpentine">
<label>Cookie-based Caching</label>
<frontend_type>text</frontend_type>
<sort_order>35</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<keys translate="label" module="turpentine">
<label>Cookie Keys</label>
<frontend_type>textarea</frontend_type>
<comment>List of cookie keys to include in caching hash key.</comment>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
</keys>
</fields>
</cookie>
<params translate="label" module="turpentine">
<label>Parameter-based Caching</label>
<frontend_type>text</frontend_type>
Expand Down
2 changes: 2 additions & 0 deletions app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ sub vcl_hash {
set req.hash += regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1");
}

{{custom_cookie_hash}}

return (hash);
}

Expand Down
2 changes: 2 additions & 0 deletions app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ sub vcl_hash {
hash_data(regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1"));
}

{{custom_cookie_hash}}

return (hash);
}

Expand Down
3 changes: 3 additions & 0 deletions app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down