5 * @subpackage plugins
\r
9 * read a cache file, determine if it needs to be
\r
10 * regenerated or not
\r
12 * @param string $tpl_file
\r
13 * @param string $cache_id
\r
14 * @param string $compile_id
\r
15 * @param string $results
\r
19 // $tpl_file, $cache_id, $compile_id, &$results
\r
21 function smarty_core_read_cache_file(&$params, &$smarty)
\r
23 static $content_cache = array();
\r
25 if ($smarty->force_compile) {
\r
26 // force compile enabled, always regenerate
\r
30 if (isset($content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']])) {
\r
31 list($params['results'], $smarty->_cache_info) = $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']];
\r
35 if (!empty($smarty->cache_handler_func)) {
\r
36 // use cache_handler function
\r
37 call_user_func_array($smarty->cache_handler_func,
\r
38 array('read', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));
\r
40 // use local cache file
\r
41 $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
\r
42 $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
\r
43 $params['results'] = $smarty->_read_file($_cache_file);
\r
46 if (empty($params['results'])) {
\r
47 // nothing to parse (error?), regenerate cache
\r
51 $cache_split = explode("\n", $params['results'], 2);
\r
52 $cache_header = $cache_split[0];
\r
54 $_cache_info = unserialize($cache_header);
\r
56 if ($smarty->caching == 2 && isset ($_cache_info['expires'])){
\r
57 // caching by expiration time
\r
58 if ($_cache_info['expires'] > -1 && (time() > $_cache_info['expires'])) {
\r
59 // cache expired, regenerate
\r
63 // caching by lifetime
\r
64 if ($smarty->cache_lifetime > -1 && (time() - $_cache_info['timestamp'] > $smarty->cache_lifetime)) {
\r
65 // cache expired, regenerate
\r
70 if ($smarty->compile_check) {
\r
71 $_params = array('get_source' => false, 'quiet'=>true);
\r
72 foreach (array_keys($_cache_info['template']) as $_template_dep) {
\r
73 $_params['resource_name'] = $_template_dep;
\r
74 if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
\r
75 // template file has changed, regenerate cache
\r
80 if (isset($_cache_info['config'])) {
\r
81 $_params = array('resource_base_path' => $smarty->config_dir, 'get_source' => false, 'quiet'=>true);
\r
82 foreach (array_keys($_cache_info['config']) as $_config_dep) {
\r
83 $_params['resource_name'] = $_config_dep;
\r
84 if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
\r
85 // config file has changed, regenerate cache
\r
92 foreach ($_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) {
\r
93 if (empty($smarty->_cache_serials[$_include_file_path])) {
\r
94 $smarty->_include($_include_file_path, true);
\r
97 if ($smarty->_cache_serials[$_include_file_path] != $_cache_serial) {
\r
102 $params['results'] = $cache_split[1];
\r
103 $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $_cache_info);
\r
105 $smarty->_cache_info = $_cache_info;
\r
109 /* vim: set expandtab: */
\r