9 * Prepend the cache information to the cache file
12 * @param string $tpl_file
13 * @param string $cache_id
14 * @param string $compile_id
15 * @param string $results
19 // $tpl_file, $cache_id, $compile_id, $results
21 function smarty_core_write_cache_file($params, &$smarty)
24 // put timestamp in cache header
25 $smarty->_cache_info
['timestamp'] = time();
26 if ($smarty->cache_lifetime
> -1){
28 $smarty->_cache_info
['expires'] = $smarty->_cache_info
['timestamp'] +
$smarty->cache_lifetime
;
30 // cache will never expire
31 $smarty->_cache_info
['expires'] = -1;
34 // collapse {nocache...}-tags
35 $params['results'] = preg_replace('!((\{nocache\:([0-9a-f]{32})#(\d+)\})'
37 .'{/nocache\:\\3#\\4\})!Us'
40 $smarty->_cache_info
['cache_serials'] = $smarty->_cache_serials
;
42 // prepend the cache header info into cache file
43 $params['results'] = serialize($smarty->_cache_info
)."\n".$params['results'];
45 if (!empty($smarty->cache_handler_func
)) {
46 // use cache_handler function
47 call_user_func_array($smarty->cache_handler_func
,
48 array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));
50 // use local cache file
52 if(!@is_writable
($smarty->cache_dir
)) {
53 // cache_dir not writable, see if it exists
54 if(!@is_dir
($smarty->cache_dir
)) {
55 $smarty->trigger_error('the $cache_dir \'' . $smarty->cache_dir
. '\' does not exist, or is not a directory.', E_USER_ERROR
);
58 $smarty->trigger_error('unable to write to $cache_dir \'' . realpath($smarty->cache_dir
) . '\'. Be sure $cache_dir is writable by the web server user.', E_USER_ERROR
);
62 $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
63 $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir
, $params['tpl_file'], $_auto_id);
64 $_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true);
65 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.write_file.php');
66 smarty_core_write_file($_params, $smarty);
71 /* vim: set expandtab: */