<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ものぐさ備忘録 &#187; cache</title>
	<atom:link href="http://www.ginriki.net/wd/category/cache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ginriki.net/wd</link>
	<description>ソフトウェア関係の話を中心とした備忘録的日記</description>
	<lastBuildDate>Sun, 11 Jul 2010 15:48:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ブラウザキャッシュの無効/有効</title>
		<link>http://www.ginriki.net/wd/2008/07/14/8/</link>
		<comments>http://www.ginriki.net/wd/2008/07/14/8/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 16:50:28 +0000</pubDate>
		<dc:creator>ginriki</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[http]]></category>

		<guid isPermaLink="false">http://www.gikogeek.net/wd/?p=8</guid>
		<description><![CDATA[ブラウザキャッシュは意識して設定しないと簡単に無効になったり有効になったりしてしまいます。
必ず無効にしたい or 必ず有効にしたいというポリシーがあるなら、きちんとした設定が必要です。
・ブラウザキャッシュを]]></description>
			<content:encoded><![CDATA[<p>ブラウザキャッシュは意識して設定しないと簡単に無効になったり有効になったりしてしまいます。<br />
必ず無効にしたい or 必ず有効にしたいというポリシーがあるなら、きちんとした設定が必要です。</p>
<p><strong>・ブラウザキャッシュを無効する方法</strong><br />
<a href="http://blog.knockoutmarch.com/2008/02/06/2323.html">http://blog.knockoutmarch.com/2008/02/06/2323.html</a><br />
より引用</p>
<div class="igBar"><span id="lhtml-3"><a href="#" onclick="javascript:showPlainTxt('html-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-3">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- メタタグに以下を記述。 --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">"Pragma"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"no-cache"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">"Cache-Control"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"no-store"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">"Cache-Control"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"no-cache"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">"Expires"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"-1"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- また、body内に以下を記述。 (for safari) --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/iframe.html"><span style="color: #000000; font-weight: bold;">&lt;iframe</span></a> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">"height:0px;width:0px;visibility:hidden"</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">"about:blank"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; this frame prevents back forward cache</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/iframe&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>・ブラウザキャッシュを有効にする方法</strong></p>
<p>そもそも、あるリンクをクリックした後のブラウザキャッシュ挙動には2パターンあることに注意<br />
1. キャッシュしてあるコンテンツが新しくなっていないかwebサーバに問い合わせる。新しくなってなければキャッシュを使う。 (Last-Modified &#038; If-Modified-Since &#038; 304 status)</p>
<p>2. webサーバに問い合わせず、キャッシュをそのまま使う (Expires or Cache-Control: max-age)</p>
<p>しかも、ブラウザによってhttpレスポンス/リクエストヘッダのLast-Modified, Expiresなどの解釈や優先順位が違うことに注意。<br />
<a href="http://labs.cybozu.co.jp/blog/kazuho/archives/2006/02/utilizing_cache.php">http://labs.cybozu.co.jp/blog/kazuho/archives/2006/02/utilizing_cache.php</a><br />
<a href="http://fdays.blogspot.com/2007/11/ie6cache-controlcache.html">http://fdays.blogspot.com/2007/11/ie6cache-controlcache.html</a></p>
<p>以上を踏まえると、PHPコンテンツに対して、ブラウザキャッシュを上記2番の方法で一定時間有効にしたいときは下記のようにしとけば良さそう ( $interval 秒だけキャッシュを有効にしたいとする）</p>
<div class="igBar"><span id="lphp-4"><a href="#" onclick="javascript:showPlainTxt('php-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-4">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"Expires: "</span> . <a href="http://www.php.net/gmdate"><span style="color:#000066;">gmdate</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"D, d M Y H:i:s"</span>, <a href="http://www.php.net/time"><span style="color:#000066;">time</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> + <span style="color:#0000FF;">$interval</span> <span style="color:#006600; font-weight:bold;">&#41;</span> . <span style="color:#FF0000;">" GMT"</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"Cache-Control: max-age="</span> . <span style="color:#0000FF;">$interval</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/header"><span style="color:#000066;">header</span></a><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#FF0000;">"Pragma: cache"</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#FF9933; font-style:italic;">// no-cache以外にすればＯＫ </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>キャッシュを無効にしたい場合も、有効にしたい場合も、同じようなhttpリクエスト項目を複数指定する必要があるのがだるい・・・</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ginriki.net/wd/2008/07/14/8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
