0

使用此代码:

<?php  
  // Define path and name of cached file    
  $cachefile = 'cache/'.date('M-d-Y').'.php';    

  // How long to keep cache file?   
  $cachetime = 18000;    

  // Is cache file still fresh? If so, serve it.     
  if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {    
     include($cachefile);        
     exit;    
  }   
  // if no file or too old, render and capture HTML page.
  ob_start();
?>


<html>        
Webpage content in here
</html>

<?php   
    // Save the cached content to a file    
    $fp = fopen($cachefile, 'w');    
    fwrite($fp, ob_get_contents());    
    fclose($fp);    

    // Send browser output    
    ob_end_flush();
?>

有没有办法使页面上的 DIV 标记免于缓存.. 我有一个可以完全缓存的页面,除了每天更新的价目表并希望阻止该 DIV 被缓存

谢谢 :)

4

2 回答 2

2

如果您的意思是 HTTP 缓存,那么不,您不能那样做。在 HTTP 缓存中,要么全有,要么全无。

如果您的意思是生成成本高昂的页面的服务器端缓存,那么您可以使用 cron 作业每 24 小时将第一次尝试查看该页面的结果缓存到磁盘一次,并将生成的页面作为普通静态页面提供服务与网络服务器。

于 2012-08-18T10:37:17.177 回答
0

您可以将更改的 div 的内容加载到 PHP 变量中并将其发送到缓存文件(基本上使用缓存文件作为带有参数的模板)。

于 2012-08-18T10:41:08.383 回答