<?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>Snow Giraffe Tech &#187; Nginx</title>
	<atom:link href="http://www.snowgiraffe.com/tech/category/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.snowgiraffe.com/tech</link>
	<description>rails, rubies, and sometimes dolphins</description>
	<lastBuildDate>Mon, 07 Jun 2010 14:36:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MULTIMONGREL! Awesome Action Caching with Rails</title>
		<link>http://www.snowgiraffe.com/tech/9/multimongrel-awesome-action-caching-with-rails/</link>
		<comments>http://www.snowgiraffe.com/tech/9/multimongrel-awesome-action-caching-with-rails/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 23:00:10 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[Caching]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[action cache]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[X-Accel-Redirect]]></category>
		<category><![CDATA[X-SendFile]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=9</guid>
		<description><![CDATA[Action Cache Plugin is super. Tweak it a little for use with multi mongrel environment!]]></description>
			<content:encoded><![CDATA[<div id="attachment_20" class="wp-caption alignright" style="width: 310px"><img class="size-medium wp-image-20" title="multiball1" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/01/multiball1-300x197.jpg" alt="playing pinball in Vegas reminded me of mongrel multi caching funtime" width="300" height="197" /><p class="wp-caption-text">playing pinball in Vegas reminded me of mongrel multi caching funtime</p></div>
<p>We really like cache with our rails at <a href="http://spongecell.com">Spongecell</a> and have been really successful with <a href="http://blog.craz8.com/pages/action-cache-plugin" target="_blank">Tom Fake&#8217;s Action Cache plugin</a> when we are unable to page cache highly demanded content.</p>
<p>One little concurrency issue that I encountered running with the Action cache plugin on multiple mongrels was one mongrel would delete (expire) a meta data file while another was simultaneously writing the meta or data file. Anyhoo, the result was an angry corrupt file that was served to other web clients. This made some of customers angry. Then I was angry. To avoid all the hatred, I patched the method <em>cached_entry</em> in <em>action_cache.rb</em> with this little change to remove the cache on exceptions. <a href="http://snowgiraffe.com/downloads/rails/action_cache.diff"><span style="color: #339966;">action_cache.diff</span></a></p>
<pre>        rescue
          remove_cache_item(controller)
          return nil
        end</pre>
<p>With that said, here are my favorite features which you will love too!<br />
<span id="more-9"></span></p>
<ul>
<li>The timer expiry. So&#8230; you can be super lazy and just expire your cache say every 10 minutes without having to write complex sweeping code that may or may not slow down some other actions.<br />
<code>@response.time_to_live = 10.minutes</code></li>
</ul>
<ul>
<li>Easy integration with  <a href="http://spongetech.wordpress.com/2007/11/13/the-complete-nginx-solution-to-sending-flowers-and-files-with-rails/">Nginx X-Accel-Redirect </a> (and Apache&#8217;s X-SendFile) to tell your web server to send the cached file downstream. This allows you to still use before and after filters, but  offloads the work the Nginx and free up your mongrels a bit to bark at someone else.</li>
</ul>
<p>For more information on rails caching, check out <a href="http://http://www.railsenvy.com/2007/2/28/rails-caching-tutorial">Gregg from Rail Envy&#8217;s</a> sweet post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/9/multimongrel-awesome-action-caching-with-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
