<?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>webdirect.no &#187; Linux</title>
	<atom:link href="http://webdirect.no/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://webdirect.no</link>
	<description></description>
	<lastBuildDate>Mon, 19 Jan 2009 20:26:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Apache caching with gzip enabled</title>
		<link>http://webdirect.no/linux/apache-caching-with-gzip-enabled/</link>
		<comments>http://webdirect.no/linux/apache-caching-with-gzip-enabled/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 21:04:21 +0000</pubDate>
		<dc:creator>Morten Jacobsen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://webdirect.no/?p=44</guid>
		<description><![CDATA[As some of you perhaps have noticed earlier, I&#8217;m using gzip compression through Apache&#8217;s mod_deflate on my mobile web application. Lately I&#8217;ve been working on a new service that load it&#8217;s content from an external XML request, and obviously this made me look for caching possibilities, either for the LWP-request behind the scenes or some [...]]]></description>
			<content:encoded><![CDATA[<p>As some of you perhaps have <a href="http://webdirect.no/web/speed-up-your-mobile-site-tm/">noticed earlier</a>, I&#8217;m using gzip compression through Apache&#8217;s <a href="http://httpd.apache.org/docs/2.2/mod/mod_deflate.html">mod_deflate</a> on my mobile web application. Lately I&#8217;ve been working on a new service that load it&#8217;s content from an external XML request, and obviously this made me look for caching possibilities, either for the LWP-request behind the scenes or some sort of front end, varnish-style caching. </p>
<p>Since my application was developed in Perl and LWP-Simple, the caching options was not to many. Using <a href="http://en.wikipedia.org/wiki/Varnish_cache">Varnish</a> caches was little to extravagant for this solution, so my eyes focused on Apaches own <a href="http://httpd.apache.org/docs/2.2/mod/mod_cache.html">mod_cache</a> module.</p>
<p><a href="http://httpd.apache.org/docs/2.2/mod/mod_cache.html">Mod_cache</a> can handle both memory- and disk caching. </p>
<h3>mod_mem_cache</h3>
<p>With simplicity in mind, I started to implement the memory solution, <a href="http://httpd.apache.org/docs/2.2/mod/mod_mem_cache.html">mod_mem_cache</a>. The amount of different pages needed simultaneous in the cache was not bigger than it would be achieved by allocating roughly 10 MB for this purpose.</p>
<p>The setup was quite easy (<a href="http://httpd.apache.org/docs/2.2/mod/mod_mem_cache.html">read about it here</a>), but it has one serious flaw &#8211; <strong>it does not support caching of compressed files</strong>. I&#8217;m not sure why, I think it has something to do with the order Apache handles these modules. </p>
<h3>mod_disk_cache</h3>
<p>Since I don&#8217;t consider disabling compression an option (<a href="http://webdirect.no/web/speed-up-your-mobile-site-tm/">see why</a>), the next module to try out was the <a href="http://httpd.apache.org/docs/2.2/mod/mod_disk_cache.html">mod_disk_cache</a>. This module caches all text files in a <em>specified directory</em>, valid for the time set in the file&#8217;s header expire time. Here is the setup I ended up using:</p>
<pre>
# your Apache httpd.conf
&lt;IfModule mod_cache.c&gt;
  &lt;IfModule mod_disk_cache.c&gt;
  CacheRoot /tmp/apache-cache
  CacheEnable disk /
  CacheDirLevels 2
  CacheDirLength 1
  CacheIgnoreCacheControl On
  CacheIgnoreNoLastMod On
  CacheIgnoreHeaders Accept Accept-Language Accept-Charset \
     Cache-Control User-Agent Cookie Host Referer
  CacheDisable /images
  CacheDisable /stylesheets
  CacheDisable /javascripts
  CacheDefaultExpire 300
  &lt;/IfModule&gt;
&lt;/IfModule&gt;
</pre>
<h3>mod_disk_cache config explained</h3>
<ul>
<li>The <code>CacheRoot</code> needs to be writeable for your Apache user. </li>
<li>In order to ignore all requests from browsers to <em>not</em> load cached files, I set <code> CacheIgnoreCacheControl On</code> </li>
<li><code> CacheIgnoreHeaders</code> lists all header entities that you want to remove from the cached file to be able to serve the same cached version to many user agents (browser types). The cached file&#8217;s header information contain these parameters if you don&#8217;t list them here, and one difference in those headers results in a new cached version of the same file.</li>
<li><code> CacheDisable </code> specifies directories not intended for caching. All flat files and images are practically served the same way from where they are, this cache function are mainly for dynamically generated content. <em>Like my Perl XML-parsing pages</em></li>
</ul>
<p>For further information, please read Apache&#8217;s highly informative <a href="http://httpd.apache.org/docs/2.2/mod/mod_disk_cache.html">documentation on mod_caching</a>.</p>
<p>I am now happily serving rather sluggish Perl-parsing-scripts blazingly fast from this simple caching mechanism!</p>
<p><img src="http://webdirect.no/wp-content/uploads/2008/08/img_0339.jpg" alt="Fisketur ved Høvringsvannet (Rondane)" title="img_0339" width="440" height="293" class="alignnone size-full wp-image-46" />Fishing at Lake Høvringen, Rondane, Norway</p>
]]></content:encoded>
			<wfw:commentRss>http://webdirect.no/linux/apache-caching-with-gzip-enabled/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

