2006年11月13日

Smarty nocache bug fix

El Hombre Gris' hack detects problem in cached tamplate at the moment when is used $smarty->display() or $smarty->fetch() so if you use following construction:

Code:

if (!$smarty->is_cached(...)) {
...set cached vars...
}
$smarty->display();



all that usually is done in ...set cached vars... will not be done when your broken cached template is rebuild with El Hombre Gris' hack.

Simple solution, that I don't like, is to use different compile_id for each template so when included templates' compile version is built it is different, than the same one for another template. Because problem is that complied includes (files with extension .inc) were recompiled after the template cache is built.

I'm testing another approach and it works for now in file: internals/core.read_cache_file.php on line 70 after

Code:

if ($smarty->caching == 2 && isset ($_cache_info['expires'])){
// caching by expiration time
if ($_cache_info['expires'] > -1 && (time() > $_cache_info['expires'])) {
// cache expired, regenerate
return false;
}
} else {
// caching by lifetime
if ($smarty->cache_lifetime > -1 && (time() - $_cache_info['timestamp'] > $smarty->cache_lifetime)) {
// cache expired, regenerate
return false;
}
}



should be added

Code:

if(!empty($_cache_info['cache_serials'])) {
foreach ($_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {
$compiled_include_ts = filemtime($_include_file_path);
if (!$compiled_include_ts || $compiled_include_ts>$_cache_info['timestamp']) { // when compiled file timestamp newer than template's one count cache as invalid
return false;
}
}
}



it works because function smarty_core_read_cache_file extract from cached templates paths to all cached includes and if their change timestamp is bigger thant change timestamp of cached template they were recomplied after building cached tamplate and so problem with nocache will rise.
But still I'm testing should I boder about cache_serials values or change time of cached includes is ok.

So nocache problem is detected in all $smarty->is_cached(), $smarty->display() and $smarty->fetch().

沒有留言: