CakePHPでのキャッシュコントロール

Webアプリケーションではキャッシュさせない実装が割と多いと思います。

CakePHP 1.3の場合、boforeFilter()に$this->disableCache()を追加するだけでキャッシュを無効化できるから楽ちんですね。ちなみにソースは以下。cake/libs/controller/controller.phpに書いてます。

function disableCache() {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}

Cache-Control: post-check/pre-checkの意味はMSDN参照。

Cache-Control: no-store, no-cache, must-revalidate/Pragma: no-cacheはIPA参照。

This entry was posted in PHP. Bookmark the permalink.

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt="">