QUIQQER - Cache Update
The Cache Module saves your page in an optimal version. Thus your page becomes faster, rises in the search engine rankings and lets also your visitors marvel.
Not only your images will be optimized, but also CSS, HTML and JavaScript. This will not only make your page smaller, but also reduce browser requests.

Repository
- https://github.com/QUIQQER/package-cache
- https://github.com/QUIQQER/QUIQQER
- Licence: GPL-3.0+
Bug Fixes
What was the issue(s)?
Crazy Caching Bug. The whole caching for the user nobody was much too strong and so, wrong user data were cached.
In order to understand the fix, the problem must first be explained.
The Problem
The caching module caches every page for the Nobody. An optimized version of the rendered page is saved. Nobody is an unregistered user in QUIQQER, that meansNobody is also every visitor to your site.
The problem with this is that, if, for example, an American comes to your site, an optimized version will be saved. Basically this is correct, but it is not correct for the country flag. I.e. if a European visits the site the next time, he has US as his country.
What was the solution?
Until the problem has been found it take a few hours. sigh
This fix unfortunately needed an update from the core. Unfortunately there was no good way to find out the area in which the user is defined. Therefore, we first outsourced the part a bit and defined an identifier.
<script id="quiqqer-user-defined">
{assign var=userCountry value=$User->getCountry()}
var QUIQQER_USER = {
id : {if $User->getId()}{$User->getId()}{else}0{/if},
name : '{$User->getName()}',
lang : '{$User->getLang()}',
country: {if $userCountry}'{$userCountry->getCode()}'{else}false{/if}
};
</script>
The important part is <script id="quiqqer-user-defined">
. The id assignment now allow other modules to access it better.
The fix in the cache module was a bit more complicated.
// replace user data
$cache = preg_replace_callback(
'/(.*)/Uis',
function () {
$Nobody = QUI::getUsers()->getNobody();
$Country = $Nobody->getCountry();
$countryCode = '';
if ($Country) {
$countryCode = $Country->getCode();
}
$user = [
'id' => 0,
'name' => $Nobody->getName(),
'lang' => $Nobody->getLang(),
'country' => $countryCode
];
return 'var QUIQQER_USER= '.json_encode($user).';';
},
$cache
);
return $cache;
What does this do?
For each request the part with quiqqer-user-defined
is searched. If quiqqer-user-defined
was found, the User Object for JavaScript is then completely replaced and rewritten.
preg_replace_callback
is structured as follows, the first argument is the search and if something is found, the callback function is executed (the second argument). The return value then overwrites the part which was found.
Why was preg_replace_callback used?
Since the caching module aims at speed, DOM in PHP is completely unacceptable as a solution. Even with preg_replace_callback we have our concerns. Unfortunately we found no other way to fix this strange bug.
Is it really so bad that the country in the cache isn't right?
Yes, it is. We had the following situation for 3 months: From time to time legal notices for Europeans were displayed and sometimes not. But when you logged in to the system it worked. When you logged out, every second time it worked and sometimes it didn't.
In addition, the error was then two weeks no longer present and then suddenly again.
Even though the fix looks quite simple, it still shows that caching is one of the hardest things in IT :D
GitHub Account
In the next days there will be a new stable version if all was tested
Thanks for reading
Hen, for PCSG Developers