SmartTemplate原理必要条件:
根据地址生成缓存
文件名
如
cache.md5(URL地址).ser
1.在缓存文件目录查找此文件名,
2.没有则生成
3.有,则判断是否已过期(设置全局过期日期),过期则重新生成
4.读取文件给用户
实例:
PHP代码:
复制内容到剪贴板
代码:
function use_cache ( $key = '' )
{
if (empty($_POST))
{
$this->cache_filename = $this->cache_dir . 'cache_' . md5($_SERVER['REQUEST_URI'] . serialize($key)) . '.ser';
if (($_SERVER['HTTP_CACHE_CONTROL'] != 'no-cache') && ($_SERVER['HTTP_PRAGMA'] != 'no-cache') && @is_file($this->cache_filename))
{
if ((time() - filemtime($this->cache_filename)) < $this->cache_lifetime)
{
readfile($this->cache_filename);
exit;
}
}
ob_start( array( &$this, 'cache_callback' ) );
}
}