Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

inconsistent cache key generation #8694

Closed
fritzmg opened this issue Apr 7, 2017 · 3 comments
Closed

inconsistent cache key generation #8694

fritzmg opened this issue Apr 7, 2017 · 3 comments
Labels
Milestone

Comments

@fritzmg
Copy link
Contributor

fritzmg commented Apr 7, 2017

There is an inconsistency with the cache key generation and usage. When a page is generated for the page cache, FrontendTemplate::addToCache always uses the current host for the cache key:
system/modules/core/classes/FrontendTemplate.php#L216-L220

$strCacheKey = \Environment::get('host') . '/empty.' . $objPage->language;
…
$strCacheKey = \Environment::get('host') . '/' . \Environment::get('request');

However, Automator::generateConfigCache always uses either the DNS setting from the page object or *:
system/modules/core/library/Contao/Automator.php#L539

$strBase = ($objPages->dns ?: '*');

So when the internal cache is active, the resulting system/cache/config/mapping.php will look like this for example:

<?php

return array (
  '*/empty.fallback' => '*/empty.de',
  '*/empty.de' => '*/empty.de',
);

But the cache file was generated with example.org/empty.de as its cache key.

This then leads to the start page never being served from the page cache, if the internal cache is built and no DNS setting was present in the website root.

This was referenced Apr 7, 2017
@leofeyer
Copy link
Member

So we need to adjust the FrontendTemplate class as follows, right?

// Server-side cache
if ($intCache > 0 && (\Config::get('cacheMode') == 'both' || \Config::get('cacheMode') == 'server'))
{
	$strBase = ($objPage->dns ?: '*');

	// If the request string is empty, use a special cache tag which considers the page language
	if (\Environment::get('request') == '' || \Environment::get('request') == 'index.php')
	{
		$strCacheKey = $strBase . '/empty.' . $objPage->language;
	}
	else
	{
		$strCacheKey = $strBase . '/' . \Environment::get('request');
	}

@leofeyer leofeyer added this to the 3.5.26 milestone Apr 18, 2017
@fritzmg
Copy link
Contributor Author

fritzmg commented Apr 18, 2017

No, if you use $strBase = ($objPage->dns ?: '*'); for both it won't work. You must use it only for the empty request.

@leofeyer
Copy link
Member

See #8695.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants