You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 16, 2018. It is now read-only.
I had the following problem when working with Zend_Cache_Frontend_Page:
We have a multilingual webseite. The user gets the webseite displayed based on a language cookie set on his client.
For this reason we have to use the COOKIE values to generate the hash id else only one language version would be cached.
When using the Fullpage Cache it was not enough for us to generate the Key based on the _COOKIE superglobal using this options:
The problem here is that there are also other COOKIES (or superglobals) which may change with every request but are totally irelevant for our full page cache.
For example Google Analytics changes it COOKIE values every request. Thus there was 0% Cache hits.
I have implemented a whitelist to use together with Zend_Cache_Frontend_Page.
Find below my adjustments. Maybe you can consider using it, if not maybe anyone else will run into the same problem.
Zend_Cache_Frontend_Page::_makePartialId() got a new parameter $whitelist
/**
* Make a partial id depending on options
*
* @param string $arrayName Superglobal array name
* @param bool $bool1 If true, cache is still on even if there are some variables in the superglobal array
* @param bool $bool2 If true, we have to use the content of the superglobal array to make a partial id
* @param mixed $whitelist If an array with more then one index then only use the defined indexes to create cache
* @return string|false Partial id (string) or false if the cache should have not to be used
*/
protected function _makePartialId($arrayName, $bool1, $bool2, $whitelist = false)
{
switch ($arrayName) {
case 'Get':
$var = $_GET;
break;
case 'Post':
$var = $_POST;
break;
case 'Session':
if (isset($_SESSION)) {
$var = $_SESSION;
} else {
$var = null;
}
break;
case 'Cookie':
if (isset($_COOKIE)) {
$var = $_COOKIE;
} else {
$var = null;
}
break;
case 'Files':
$var = $_FILES;
break;
default:
return false;
}
if ($bool1) {
if ($bool2) {
// We have a whitelist so only return the defined indexes.
if (true === is_array($whitelist) && count($whitelist) > 0) {
$tmpArray = array();
foreach ($whitelist as $index) {
if (true === isset($var[$index])) {
$tmpArray[$index] = $var[$index];
}
}
if (count($tmpArray) > 0) {
return serialize($tmpArray);
}
return '';
}
return serialize($var);
}
return '';
}
if (count($var) > 0) {
return false;
}
return '';
}
Zend_Cache_Frontend_Page::_makeId() calls self::_makePartialId() and thus has to be adjusted too
Jira Information
Description
Hi,
I had the following problem when working with Zend_Cache_Frontend_Page:
We have a multilingual webseite. The user gets the webseite displayed based on a language cookie set on his client.
For this reason we have to use the COOKIE values to generate the hash id else only one language version would be cached.
When using the Fullpage Cache it was not enough for us to generate the Key based on the _COOKIE superglobal using this options:
The problem here is that there are also other COOKIES (or superglobals) which may change with every request but are totally irelevant for our full page cache.
For example Google Analytics changes it COOKIE values every request. Thus there was 0% Cache hits.
I have implemented a whitelist to use together with Zend_Cache_Frontend_Page.
Find below my adjustments. Maybe you can consider using it, if not maybe anyone else will run into the same problem.
In Zend_Cache_Frontend_Page:
Zend_Cache_Frontend_Page::_makePartialId() got a new parameter $whitelist
Zend_Cache_Frontend_Page::_makeId() calls self::_makePartialId() and thus has to be adjusted too
Now you can easly define which GET, POST, COOKIE,SERVER or FILES indexes should be used to generate the Cache id.
The text was updated successfully, but these errors were encountered: