ceejayozが言ったことまたは、アプリケーションのブートストラップにキャッシュヘッダーを追加することができます。これは、必要なだけ何年もの間キャッシュを使用できます。
ページをクライアント側でキャッシュする時間数で添付関数を呼び出します。session_startはキャッシュを妨げるヘッダーを発行するため、この関数がある場合は、session_startの後に必ず呼び出してください。
function client_side_cache($hours)
{
//in the event a session start is used, I have to clean all the #$%# headers it sends to prevent caching
header('Cache-Control: ',true);
header("Pragma: ", true);
header("Expires: ", true);
//get the If-Modified-Since header in a unix time format
$headers = getallheaders();
if (isset($headers['If-Modified-Since']))
{
$modifiedSince = explode(';', $headers['If-Modified-Since']);
$modifiedSince = strtotime($modifiedSince[0]);
}
else
{
$modifiedSince = 0;
}
//calculate the Last-Modified timestamp
$current_time=time();
$last_modified=($current_time)/($hours*3600);
$last_modified=(int)$last_modified;
$last_modified=$last_modified*$hours*3600;
//check cache not expires
if ($last_modified <= $modifiedSince)
{
header('HTTP/1.1 304 Not Modified');
exit();
}
else //emit a new Last-Modified (either cache expired or page wasn'r cached
{
Header('Last-Modified: '.gmdate("D, d M Y H:i:s",$last_modified).' GMT ');
}
}