discard $_cache_info when the cache should be regenerated

This commit is contained in:
messju
2003-08-22 14:02:15 +00:00
parent 124d86de0d
commit 786d110c89

View File

@@ -51,47 +51,45 @@ function smarty_core_read_cache_file(&$params, &$smarty)
$cache_split = explode("\n", $params['results'], 2); $cache_split = explode("\n", $params['results'], 2);
$cache_header = $cache_split[0]; $cache_header = $cache_split[0];
$smarty->_cache_info = unserialize($cache_header); $_cache_info = unserialize($cache_header);
if ($smarty->caching == 2 && isset ($smarty->_cache_info['expires'])){ if ($smarty->caching == 2 && isset ($_cache_info['expires'])){
// caching by expiration time // caching by expiration time
if ($smarty->_cache_info['expires'] > -1 && (time() > $smarty->_cache_info['expires'])) { if ($_cache_info['expires'] > -1 && (time() > $_cache_info['expires'])) {
// cache expired, regenerate // cache expired, regenerate
return false; return false;
} }
} else { } else {
// caching by lifetime // caching by lifetime
if ($smarty->cache_lifetime > -1 && (time() - $smarty->_cache_info['timestamp'] > $smarty->cache_lifetime)) { if ($smarty->cache_lifetime > -1 && (time() - $_cache_info['timestamp'] > $smarty->cache_lifetime)) {
// cache expired, regenerate // cache expired, regenerate
return false; return false;
} }
} }
if ($smarty->compile_check) { if ($smarty->compile_check) {
$_params = array('get_source' => false); $_params = array('get_source' => false, 'quiet'=>true);
foreach (array_keys($smarty->_cache_info['template']) as $_template_dep) { foreach (array_keys($_cache_info['template']) as $_template_dep) {
$_params['resource_name'] = $_template_dep; $_params['resource_name'] = $_template_dep;
$smarty->_fetch_resource_info($_params); if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
if ($smarty->_cache_info['timestamp'] < $_params['resource_timestamp']) {
// template file has changed, regenerate cache // template file has changed, regenerate cache
return false; return false;
} }
} }
if (isset($smarty->_cache_info['config'])) { if (isset($_cache_info['config'])) {
$_params = array('resource_base_path' => $smarty->config_dir, 'get_source' => false); $_params = array('resource_base_path' => $smarty->config_dir, 'get_source' => false, 'quiet'=>true);
foreach (array_keys($smarty->_cache_info['config']) as $_config_dep) { foreach (array_keys($_cache_info['config']) as $_config_dep) {
$_params['resource_name'] = $_config_dep; $_params['resource_name'] = $_config_dep;
$smarty->_fetch_resource_info($_params); if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
if ($smarty->_cache_info['timestamp'] < $_params['resource_timestamp']) { // config file has changed, regenerate cache
// config file has changed, regenerate cache return false;
return false; }
}
} }
} }
} }
foreach ($smarty->_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) { foreach ($_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {
if (empty($smarty->_cache_serials[$_include_file_path])) { if (empty($smarty->_cache_serials[$_include_file_path])) {
$smarty->_include($_include_file_path, true); $smarty->_include($_include_file_path, true);
} }
@@ -102,8 +100,9 @@ function smarty_core_read_cache_file(&$params, &$smarty)
} }
} }
$params['results'] = $cache_split[1]; $params['results'] = $cache_split[1];
$content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $smarty->_cache_info); $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $_cache_info);
$smarty->_cache_info = $_cache_info;
return true; return true;
} }