background image

 

 

function

 page_cache(

$ttl

 = 0) 

$ttl

 = 

$ttl

 ? 

$ttl

 : PAGE_TTL;

//缓存时间,默认 3600s 

$contents

 = ob_get_contents();

//

 

从缓存中获取内容

$contents

 = "<!--page_ttl:".(time() + 

$ttl

)."-->\n".

$contents

  

//加上自定义头部:过期时间=生成时间+

 

缓存时间

file_put_contents

(PAGE_FILE, 

$contents

);

//

 

写入缓存文件中

ob_end_flush();

//

 

释放缓存


 
3.函数使用,注意这两个函数有先后执行顺序,还有别忘了 ob_start() 
代码如下:
 
<?php 
page_init();

//

 

页面缓存初始化

ob_start();

//

 

开启缓存

 
...

//

 

代码段

 
page_cache(60);

//

 

一般是最后一行

 
?>