contao/import — Issue #2654: index page caching 
Author: importer
Created: 2011-11-29 19:55:43+00:00
State: open
Labels: Defect, frontend, Invalid

Hello,

I have run across a problem: home page generates very high system load.
I found out that index page calls (not all) executes about 170 sql queries every time.

Contao use following file name for reading page from cache (code from index.php)

```
if ($this->Environment->request == '' || $this->Environment->request == 'index.php')
{
$strCacheKey = $this->Environment->base .'empty.'. $this->Environment->httpAcceptLanguage[0];
}
else
{
$strCacheKey = $this->Environment->base . $this->Environment->request;
}
$strCacheFile = TL_ROOT . '/system/tmp/' . md5($strCacheKey);
```

When Contao writes cache to disk , it uses following file name (code from FrontendTemplate.php )

```
if ($this->Environment->request == '' || $this->Environment->request == 'index.php')
{
$strUniqueKey = $this->Environment->base . 'empty.' . $objPage->language;
}
else
{
$strUniqueKey = $this->Environment->base . $strUrl;
}
$objFile = new File('system/tmp/' . md5($strUniqueKey));
```

Difference only in postfix: $this->Environment->httpAcceptLanguage[0] and $objPage->language

```
// here contao define key for reading from cache
$strCacheKey = $this->Environment->base .'empty.'. $this->Environment->httpAcceptLanguage[0];

// here contao define key for writing to cache
$strUniqueKey = $this->Environment->base . 'empty.' . $objPage->language;
```

I tried to request index page from 1st browser.
/system/tmp folder was empty , so cache file was created

```
md5( 'www.domain.com/empty.en')
```

that I requested index page second time , and it was read from cache

```
md5('www.domain.com/empty.en')
```

that I opened another browser, and requested index page.
Contao tried to read cache from

```
md5('www.domain.com/empty.ru');
```

this file doesn't exist, so contao write cache to

```
md5('www.domain.com/empty.en')
```

Contao tries to read cache from md5('www.domain.com/empty.[u]ru[/u]') , it doesn't exists, Contao generates page and writes cache to md5('www.domain.com/empty.en')

In my case cache doesn't work because httpAcceptLanguage and objPage->language are different.

I applied temporary fix

```
if ($this->Environment->request == '' || $this->Environment->request == 'index.php')
{
$strCacheKey = $this->Environment->base .'empty.en';
}
else
...
```

--- _Originally created by igolikov on November 2nd, 2010, at 02:25pm (ID 2654)_