/** * 检查缓存文件是否有效 * 如果无效则需要重新编译 * @access public * @param string $tmplTemplateFile 模板文件名 * @return boolean */ protected function checkCache($tmplTemplateFile, $prefix = '') { if (!C('TMPL_CACHE_ON')) { // 优先对配置设定检测 return false; } $tmplCacheFile = C('CACHE_PATH') . $prefix . md5($tmplTemplateFile) . C('TMPL_CACHFILE_SUFFIX'); if (!Storage::has($tmplCacheFile, 'tpl')) { return false; } elseif (filemtime($tmplTemplateFile) > Storage::get($tmplCacheFile, 'mtime', 'tpl')) { // 模板文件如果有更新则缓存需要更新 return false; } elseif (C('TMPL_CACHE_TIME') != 0 && time() > Storage::get($tmplCacheFile, 'mtime', 'tpl') + C('TMPL_CACHE_TIME')) { // 缓存是否在有效期 return false; } // 开启布局模板 if (C('LAYOUT_ON')) { $layoutFile = THEME_PATH . C('LAYOUT_NAME') . C('TMPL_TEMPLATE_SUFFIX'); if (filemtime($layoutFile) > Storage::get($tmplCacheFile, 'mtime', 'tpl')) { return false; } } // 缓存有效 return true; }
public static function fileMTime($cacheFile) { static $_fmt = array(); if (isset($_fmt[$cacheFile])) { return $_fmt[$cacheFile]; } $_fmt[$cacheFile] = Storage::get($cacheFile, 'mtime', 'html'); return $_fmt[$cacheFile]; }
/** * 检查静态HTML文件是否有效 * 如果无效需要重新更新 * @access public * @param string $cacheFile 静态文件名 * @param integer $cacheTime 缓存有效期 * @return boolean */ public static function checkHTMLCache($cacheFile = '', $cacheTime = '') { if (!is_file($cacheFile) && 'sae' != APP_MODE) { return false; } elseif (filemtime(\Think\Think::instance('Think\\View')->parseTemplate()) > Storage::get($cacheFile, 'mtime', 'html')) { // 模板文件如果更新静态文件需要更新 return false; } elseif (!is_numeric($cacheTime) && function_exists($cacheTime)) { return $cacheTime($cacheFile); } elseif ($cacheTime != 0 && NOW_TIME > Storage::get($cacheFile, 'mtime', 'html') + $cacheTime) { // 文件是否在有效期 return false; } //静态文件有效 return true; }
/** * 检查静态HTML文件是否有效 * 如果无效需要重新更新 * @access public * @param string $cacheFile 静态文件名 * @param integer $cacheTime 缓存有效期 * @return boolean */ public static function checkHTMLCache($cacheFile = '', $cacheTime = '') { if (!is_file($cacheFile) && 'sae' != APP_MODE) { return false; } elseif (filemtime(C('TEMPLATE_NAME')) > Storage::get($cacheFile, 'mtime', 'html')) { // 模板文件如果更新静态文件需要更新 return false; } elseif (!is_numeric($cacheTime) && function_exists($cacheTime)) { return $cacheTime($cacheFile); } elseif ($cacheTime != 0 && NOW_TIME > Storage::get($cacheFile, 'mtime', 'html') + $cacheTime) { // 文件是否在有效期 return false; } //静态文件有效 return true; }