• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Smarty/libs/internals/core.read_cache_file.php

00001 <?php
00019 //  $tpl_file, $cache_id, $compile_id, &$results
00020 
00021 function smarty_core_read_cache_file(&$params, &$smarty)
00022 {
00023     static  $content_cache = array();
00024 
00025     if ($smarty->force_compile) {
00026         // force compile enabled, always regenerate
00027         return false;
00028     }
00029 
00030     if (isset($content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']])) {
00031         list($params['results'], $smarty->_cache_info) = $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']];
00032         return true;
00033     }
00034 
00035     if (!empty($smarty->cache_handler_func)) {
00036         // use cache_handler function
00037         call_user_func_array($smarty->cache_handler_func,
00038                              array('read', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null));
00039     } else {
00040         // use local cache file
00041         $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']);
00042         $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id);
00043         $params['results'] = $smarty->_read_file($_cache_file);
00044     }
00045 
00046     if (empty($params['results'])) {
00047         // nothing to parse (error?), regenerate cache
00048         return false;
00049     }
00050 
00051     $_contents = $params['results'];
00052     $_info_start = strpos($_contents, "\n") + 1;
00053     $_info_len = (int)substr($_contents, 0, $_info_start - 1);
00054     $_cache_info = unserialize(substr($_contents, $_info_start, $_info_len));
00055     $params['results'] = substr($_contents, $_info_start + $_info_len);
00056 
00057     if ($smarty->caching == 2 && isset ($_cache_info['expires'])){
00058         // caching by expiration time
00059         if ($_cache_info['expires'] > -1 && (time() > $_cache_info['expires'])) {
00060             // cache expired, regenerate
00061             return false;
00062         }
00063     } else {
00064         // caching by lifetime
00065         if ($smarty->cache_lifetime > -1 && (time() - $_cache_info['timestamp'] > $smarty->cache_lifetime)) {
00066             // cache expired, regenerate
00067             return false;
00068         }
00069     }
00070 
00071     if ($smarty->compile_check) {
00072         $_params = array('get_source' => false, 'quiet'=>true);
00073         foreach (array_keys($_cache_info['template']) as $_template_dep) {
00074             $_params['resource_name'] = $_template_dep;
00075             if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
00076                 // template file has changed, regenerate cache
00077                 return false;
00078             }
00079         }
00080 
00081         if (isset($_cache_info['config'])) {
00082             $_params = array('resource_base_path' => $smarty->config_dir, 'get_source' => false, 'quiet'=>true);
00083             foreach (array_keys($_cache_info['config']) as $_config_dep) {
00084                 $_params['resource_name'] = $_config_dep;
00085                 if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) {
00086                     // config file has changed, regenerate cache
00087                     return false;
00088                 }
00089             }
00090         }
00091     }
00092 
00093     $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $_cache_info);
00094 
00095     $smarty->_cache_info = $_cache_info;
00096     return true;
00097 }
00098 
00099 /* vim: set expandtab: */
00100 
00101 ?>

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2