<?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>Kaizou &#187; cache</title>
	<atom:link href="http://www.kaizou.org/tag/cache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kaizou.org</link>
	<description>This is Web 2.71828</description>
	<lastBuildDate>Thu, 24 Nov 2011 09:34:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>HTML 5 offline web applications</title>
		<link>http://www.kaizou.org/2009/04/html-5-offline-web-applications/</link>
		<comments>http://www.kaizou.org/2009/04/html-5-offline-web-applications/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 17:21:21 +0000</pubDate>
		<dc:creator>David Corvoysier</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[cache-manifest]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[offline]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.kaizou.org/?p=355</guid>
		<description><![CDATA[HTML 5 provides a new caching feature to support offline web applications. Basically, you can specify in a specific file called the &#8220;cache manifest&#8221; the caching policy to apply to a particular web page. To activate the HTML 5 caching feature for a specific document, you only need to specify the URI of the cache [...]]]></description>
			<content:encoded><![CDATA[<p>HTML 5 provides a new caching feature to support <a href="http://www.w3.org/TR/offline-webapps/" alt="HTML 5 offline web applications">offline web applications</a>.</p>
<p>Basically, you can specify in a specific file called the &#8220;cache manifest&#8221; the caching policy to apply to a particular web page.</p>
<p>To activate the HTML 5 caching feature for a specific document, you only need to specify the URI of the cache manifest file in the <code>manifest</code> attribute of the <code>&lt;html&gt;</code> element.</p>
<pre>
<code>&lt;!DOCTYPE HTML&gt;
&lt;html manifest="myapp.cache"&gt;
...</code>
</pre>
<p>The file that references the cache manifest file is called the <a href="http://www.whatwg.org/specs/web-apps/current-work/#concept-appcache-master" alt="HTML 5 cache master entry">master entry</a>.</p>
<p>Please note that to be properly parsed by the browser, the manifest file must have a <code>text/cache-manifest</code> MIME type (which means that you will need either to add a custom file type extension binding to your web server or to specify manually the mime-type, for instance using PHP <code>header</code> directive).</p>
<p>A cache manifest file typically looks like this:</p>
<pre>
<code>CACHE MANIFEST
index.html
style.css
images/logo.png

NETWORK:
search.php</code>
</pre>
<p>This file specifies several files to cache (the cache <a href="http://www.whatwg.org/specs/web-apps/current-work/#concept-appcache-explicit" alt="HTML 5 cache explicit entries">explicit entries</a>), and then specifies that search.php should never be cached (it is said to belong to the <a href="http://www.whatwg.org/specs/web-apps/current-work/#concept-appcache-onlinewhitelist" alt="HTML 5 cache online white-list">online white list</a>), so that any attempt to access that file will bypass the cache.</p>
<p>Whenever the user browses to the page corresponding to a document to which a cache manifest is associated, the browser must check on the server if the latter has been modified:</p>
<ul>
<li>If it hasn&#8217;t, then the cached content is used,</li>
<li>If a new version of the cache manifest exists, then the cached content is considered as staled and reloaded from the server.</li>
</ul>
<p>The cache manifest for a document may also contain <a href="http://www.whatwg.org/specs/web-apps/current-work/#concept-appcache-fallback" alt="HTML 5 cache fallback entries">fallback entries</a> that can be used if the browser can&#8217;t retrieve the original content. Below is an example where a static image is used when the retrieval of a dynamically generated image fails:</p>
<pre>
<code>CACHE MANIFEST
FALLBACK:
images/mirror-effect.php server-busy.jpg</code>
</pre>
<p>HTML 5 also defines an <a href="http://www.whatwg.org/specs/web-apps/current-work/#application-cache-api" alt="HTML 5 application cache API">application cache API</a> to manually trigger cache updates:</p>
<ul>
<li><a href="http://www.whatwg.org/specs/web-apps/current-work/#dom-appcache-update" alt="HTML 5 cache update method"><code>update()</code></a>: updates the cache for the current document in the background,</li>
<li><a href="http://www.whatwg.org/specs/web-apps/current-work/#dom-appcache-swapcache" alt="HTML 5 swap cache method"><code>swapCache()</code></a>: reflow the HTML document using updated cached content,</li>
<li><a href="http://www.whatwg.org/specs/web-apps/current-work/#handler-appcache-onupdateready" alt="HTML 5 cache updateready event"><code>onupdateready()</code></a>: event triggered when the cache content has been updated,</li>
<li><a href="http://www.whatwg.org/specs/web-apps/current-work/#handler-appcache-onobsolete" alt="HTML 5 cache obsolete event"><code>onobsolete()</code></a>: event triggered when the cache content has been marked as obsolete,</li>
<li>&#8230;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.kaizou.org/2009/04/html-5-offline-web-applications/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Browser HTTP 1.1 caching compliancy test</title>
		<link>http://www.kaizou.org/2009/03/browser-http-11-caching-compliancy-test/</link>
		<comments>http://www.kaizou.org/2009/03/browser-http-11-caching-compliancy-test/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 15:20:21 +0000</pubDate>
		<dc:creator>David Corvoysier</dc:creator>
				<category><![CDATA[HTTP]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.kaizou.org/?p=310</guid>
		<description><![CDATA[Following a previous post about HTTP 1.1 caching mechanisms, I have been asked whether common browsers were actually compliant or not, so I wrote a little test to verify if at least basic features were supported. The results for your browser will appear in the frame below. Update: This is a new version with cache [...]]]></description>
			<content:encoded><![CDATA[<p>Following a previous post about <a href="/2009/02/http-caching-explained/">HTTP 1.1 caching mechanisms</a>, I have been asked whether common browsers were actually compliant or not, so I wrote a little test to verify if at least basic features were supported.</p>
<p>The results for your browser will appear in the frame below.</p>
<p><object type="text/html" data="/code/cache/index.html"></object></p>
<p>Update: This is a new version with cache headers completely handled by PHP instead of using apache mod_expires. I had to do this because I could&#8217;nt deactivate chunk transfer encoding of pages generated by php on my host, and this prevents HTTP 1.1 caching headers to be inserted by apache &#8230; the test seems to work now, but it is still in beta</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kaizou.org/2009/03/browser-http-11-caching-compliancy-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sample Apache cache configuration</title>
		<link>http://www.kaizou.org/2009/02/sample-apache-cache-configuration/</link>
		<comments>http://www.kaizou.org/2009/02/sample-apache-cache-configuration/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 12:33:46 +0000</pubDate>
		<dc:creator>David Corvoysier</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[cache]]></category>

		<guid isPermaLink="false">http://www.kaizou.org/?p=137</guid>
		<description><![CDATA[The Apache 2 web server can be configured to define a custom cache policy, allowing a fine-grained control over your web site content lifecycle in browser caches. This article provides a step-by-step simple configuration sample. The reader is invited to read first this other article presenting the HTTP 1.1 cache mechanisms. Step 1: Activate expiration [...]]]></description>
			<content:encoded><![CDATA[<p><span>The Apache 2 web server can be configured to define a custom cache policy, allowing a fine-grained control over your web site content lifecycle in browser caches. This article provides a step-by-step simple configuration sample. The reader is invited to read first this other article presenting the <a title="HTTP caching explained" href="/2009/02/http-caching-explained/" target="_self">HTTP 1.1 cache mechanisms</a>.<br />
</span></p>
<h3>Step 1: Activate expiration module</h3>
<p>By default, Apache 2 doesn&#8217;t insert any expiration header in served documents. This feature is provided by a specific module, <a title="Apache 2 mod_expires module" href="http://httpd.apache.org/docs/2.0/mod/mod_expires.html" target="_self">mod_expires</a>.</p>
<p>Two operations are required to activate the feature:<br />
•    add mod_expires to the list of enabled modules,</p>
<pre><code>a2enmod expires</code></pre>
<p>•    add the ExpiresActive On directive to the site configuration.</p>
<pre>
<code>NameVirtualHost *
&lt;VirtualHost&gt;
...
   &lt;Directory /var/www/mysite&gt;
      <strong>ExpiresActive On</strong>
   &lt;/Directory&gt;
...
&lt;/VirtualHost&gt;</code>
</pre>
<h3>Step 2: Define a default expiration policy</h3>
<p>A default expiration policy that applies to all documents can be specified using the ExpiresDefault directive.</p>
<p>I would recommend to define the default expiration period to a very short value, in order to avoid client browsers keeping forever in cache documents for which you forgot to provide an explicit expiration period (see next paragraphs).</p>
<pre>
<code>NameVirtualHost *
&lt;VirtualHost&gt;
...
   &lt;Directory /var/www/mysite&gt;
      ExpiresActive On
      <strong>ExpiresDefault "access plus 10 minutes"</strong>
   &lt;/Directory&gt;
...
&lt;/VirtualHost&gt;</code>
</pre>
<h3>Step 3: Define an expiration date per document type</h3>
<p>A specific expiration policy can be defined for each document type using the ExpiresByType directive.</p>
<p>It is for instance possible to define an explicit expiration policy for HTML pages, javascript, images and json text files in order to control their lifetime in the browser cache, and avoid unnecessary validity checks from the client.</p>
<pre>
<code>NameVirtualHost *
&lt;VirtualHost&gt;
...
   &lt;Directory /var/www/mysite&gt;
      ExpiresActive On
      ExpiresDefault "access plus 10 minutes"
<strong>
      ExpiresByType text/html "access plus 1 day"
      ExpiresByType text/javascript "access plus 1 day"
      ExpiresByType text/x-json "access plus 1 day"

      ExpiresByType image/gif "access plus 1 month"
      ExpiresByType image/png "access plus 1 month"
      ExpiresByType image/jpg "access plus 1 month"
</strong>
   &lt;/Directory&gt;
...
&lt;/VirtualHost&gt;</code>
</pre>
<p>Note: The apache 2 web server uses the MIME-type to categorize documents. In order to have the proper directive applied to them, JSON text files must be sent as text/x-json documents.</p>
<h3>Step 4: Mark session-specific documents as non-cacheable</h3>
<p>Even if a large part of a specific site might be cacheable without disturbing the service, some specific documents are purely dynamic (like the results of a search query for instance) and must not be cached.</p>
<p>Fortunately enough, it is allowed to define exceptions to the general expiration policy defined for a given file type, using file pattern matching with the FilesMatch directive.</p>
<p>Thus, it is possible to specify that a Cache-Control header corresponding to &#8220;no-cache&#8221; be inserted for all files matching a given criteria, that can be based on a regular expression.</p>
<p>The Header directive is used to insert specific Cache-control values. It is provided by the <a title="Apache 2 mod_header module" href="http://httpd.apache.org/docs/2.0/mod/mod_headers.html" target="_self">mod_header</a> module, which is activated by default.</p>
<pre>
<code>NameVirtualHost *
&lt;VirtualHost&gt;
...
   &lt;Directory /var/www/mysite&gt;
      ExpiresActive On
      ExpiresDefault "access plus 10 minutes"
      ExpiresByType text/html "access plus 1 day"
      ExpiresByType text/javascript "access plus 1 day"
      ExpiresByType text/x-json "access plus 1 day"

      ExpiresByType image/gif "access plus 1 month"
      ExpiresByType image/png "access plus 1 month"
      ExpiresByType image/jpg "access plus 1 month"

<strong>
      &lt;FilesMatch "searchResults.html"&gt;
            Header set Cache-control "no-cache"
      &lt;/FilesMatch&gt;
</strong>
   &lt;/Directory&gt;
...
&lt;/VirtualHost&gt;</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kaizou.org/2009/02/sample-apache-cache-configuration/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>HTTP caching explained</title>
		<link>http://www.kaizou.org/2009/02/http-caching-explained/</link>
		<comments>http://www.kaizou.org/2009/02/http-caching-explained/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 13:08:44 +0000</pubDate>
		<dc:creator>David Corvoysier</dc:creator>
				<category><![CDATA[HTTP]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[expiration]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.kaizou.org/?p=106</guid>
		<description><![CDATA[Web developers can take advantage of HTTP caching mechanisms to improve significantly the performance and the robustness of their site. HTTP caching mechanisms are however not well-known and often not-well understood. This article aims at clarifying things without going into too much details. For a more complete description of these mechanisms, please refer to the [...]]]></description>
			<content:encoded><![CDATA[<p>Web developers can take advantage of HTTP caching mechanisms to improve significantly the performance and the robustness of their site.</p>
<p>HTTP caching mechanisms are however not well-known and often not-well understood. This article aims at clarifying things without going into too much details.</p>
<p>For a more complete description of these mechanisms, please refer to the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13">HTTP/1.1 RFC</a>.</p>
<p>The HTTP/1.1 protocol includes two basic &#8220;caching&#8221; mechanisms to:</p>
<ul>
<li>eliminate the need to send requests in many cases, using an &#8220;expiration&#8221; mechanism,</li>
<li>eliminate the need to send full responses in many other cases, using a &#8220;validation&#8221; mechanism.</li>
</ul>
<h3>The HTTP/1.1 Expiration model</h3>
<p>The HTTP/1.1 expiration model, as defined in [<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.2">RFC2616 §13.2</a>], is designed to avoid the client making requests to the origin server until the corresponding content has expired.</p>
<p>The HTTP/1.1 expiration model does not mandate that the origin server explicitly specifies expiration dates for contents. For that reason, each client needs to define its own caching algorithm.</p>
<p>Note: A simple algorithm is provided in [<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.2">RFC2616 §13.2</a>], based on the last modification date of a document. If that information is provided, then the expiration date equals ten percent of the difference between the reception date and the modification date.</p>
<p>However, deterministic client behaviour is often desirable to avoid server congestion, and two headers can be used to explicitly specify the expiration date of a particular content:<br />
•	Expires (see [<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21">RFC2616 §14.21</a>]),<br />
•	Cache-control, max-age directive (see [<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9">RFC2616 §14.9</a>]).</p>
<p>Note: The Cache-control header always takes precedence over the Expires header</p>
<p>Example:</p>
<p>A page that expires in ten minutes (see how both headers are here redundant)</p>
<pre>HTTP/1.1 200 OK
Date: Mon 06 Oct 2008 12:33:48 GMT
Server: Apache/2.2.8
Cache-Control: max-age=600
Expires: Mon 06 Oct 2008 12:43:48 GMT</pre>
<p>More, the Cache-control header can also be used to further control the cache handling on the client side, by using a set of directives that directly control the client caching algorithm.</p>
<p>Example:</p>
<p>Never cache this page (Expires header will be ignored):</p>
<pre>HTTP/1.1 200 OK
Date: Mon 06 Oct 2008 12:33:48 GMT
Server: Apache/2.2.8
Cache-Control: no-cache
Expires: Mon 06 Oct 2008 12:43:48 GMT</pre>
<p>Always revalidate this page (Expires header will be ignored):</p>
<pre>HTTP/1.1 200 OK
Date: Mon 06 Oct 2008 12:33:48 GMT
Server: Apache/2.2.8
Cache-Control: must-revalidate
Expires: Mon 06 Oct 2008 12:43:48 GMT</pre>
<h3>The HTTP/1.1 Validation model</h3>
<p>The HTTP/1.1 validation model, as defined in [<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3">RFC2616 §13.3</a>], is designed to request the client to verify first if a content has changed before fetching it from the server.</p>
<p>To verify if a stale cache entry is still valid, the client simply inserts specific headers in the request it sends to the origin server, passing back a specific tag it has received in the initial request. If the origin server recognizes that the tag corresponds to a content that hasn&#8217;t changed, it responds with a &#8220;304 Not Modified&#8221;. Otherwise, it sends back the updated document.</p>
<p>Note: Hints that this mechanism is at work can thus be found by looking for &#8220;304 Not Modified&#8221; responses in the web server logs.</p>
<p>The following two headers are typically used to tag a particular content:<br />
•	Last-Modified (see [<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.29">RFC2616 §14.29</a>]),<br />
•	Etag (see [<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19">RFC2616 §14.19</a>]).</p>
<h3>Caching documents retrieved through HTTPS</h3>
<p>By default, most browsers do not cache documents retrieved through HTTPS for security reasons.</p>
<p>However, the origin server can use the Cache-Control header to specify that a specific document is public, and can thus be cached.</p>
<p>Example:</p>
<pre>HTTP/1.1 200 OK
Date: Mon 06 Oct 2008 12:33:48 GMT
Server: Apache/2.2.8
Cache-Control: public
Expires: Mon 06 Oct 2008 12:43:48 GMT</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kaizou.org/2009/02/http-caching-explained/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

