<?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; Caching</title>
	<atom:link href="http://www.snowgiraffe.com/tech/category/ruby-on-rails/caching/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>Delectable plugin treats for the ruby shovers</title>
		<link>http://www.snowgiraffe.com/tech/545/delectable-plugin-treats-for-the-ruby-shovers/</link>
		<comments>http://www.snowgiraffe.com/tech/545/delectable-plugin-treats-for-the-ruby-shovers/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 20:45:37 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ActiveRecord Dumper]]></category>
		<category><![CDATA[AR Dumper]]></category>
		<category><![CDATA[Asset Tag Extensions]]></category>
		<category><![CDATA[Google Base4r]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Ruby Prof]]></category>
		<category><![CDATA[Ruby Prof Request Filters]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=545</guid>
		<description><![CDATA[Been a long time. shouldn&#8217;t of left ya without a dope plugin to step to. meh. But for reals, I&#8217;ve been working way too much. Here&#8217;s a tasty sampler of some new and revived github projects:

ActiveRecord Dumper
Asset Tag Extensions
Ruby Prof Request Filters
Google Base4r extensions

ActiveRecord Dumper
script/plugin install http://github.com/blythedunham/ar_dumper
Dumper. I barely know her! I wrote this ages [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_555" class="wp-caption alignright" style="width: 160px"><img class="size-thumbnail wp-image-555  " style="margin-left: 5px;" title="candy_sampler" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/08/candy_sampler-150x150.jpg" alt="Candy raver plugin funtime!" width="150" height="150" /><p class="wp-caption-text">Delicatable treats for the rubies.</p></div>
<p>Been a long time. shouldn&#8217;t of left ya without a dope plugin to step to. meh. But for reals, I&#8217;ve been working way too much. Here&#8217;s a tasty sampler of some new and revived github projects:</p>
<ul>
<li><a href="http://github.com/blythedunham/asset_tag_extensions">ActiveRecord Dumper</a></li>
<li><a href="http://github.com/blythedunham/asset_tag_extensions">Asset Tag Extensions</a></li>
<li><a href="http://github.com/blythedunham/ruby_prof_request_filters/">Ruby Prof Request Filters</a></li>
<li><a href="http://github.com/blythedunham/base4r/">Google Base4r extensions</a></li>
</ul>
<h2><a href="http://github.com/blythedunham/asset_tag_extensions">ActiveRecord Dumper</a></h2>
<pre>script/plugin install http://github.com/blythedunham/ar_dumper</pre>
<p>Dumper. I barely know her! I wrote this ages ago back in the Rails 1 dot 0h(mg) daze, but still works like a charm.</p>
<p>Easily export records to csv, yaml, or xml using the <tt>:find</tt> options, or <span style="color: #ff0000;">(new) </span>specify an array of activerecords with the <tt>:records</tt> option. AR Dumper dumps to strings or files with a paginated option, and it supports full customization of displayed headers and content with options such as  <tt> <img src='http://www.snowgiraffe.com/tech/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly, :export, :procs, :methods</tt></p>
<pre class="ruby"><span class="constant">Book</span><span class="punct">.</span><span class="ident">dumper</span> <span class="symbol">:yml</span><span class="punct">,</span> <span class="symbol">:find</span> <span class="punct">=&gt;</span> <span class="punct">{</span><span class="symbol">:conditions</span> <span class="punct">=&gt;</span> <span class="punct">['</span><span class="string">author_name like ?</span><span class="punct">',</span> <span class="punct">'</span><span class="string">snowgiraffe</span><span class="punct">']</span> <span class="punct">}</span>

<span class="constant">Book</span><span class="punct">.</span><span class="ident">dumper</span> <span class="symbol">:csv</span><span class="punct">,</span> <span class="symbol"> <img src='http://www.snowgiraffe.com/tech/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly</span> <span class="punct">=&gt;</span> <span class="punct">[</span><span class="symbol">:author_name</span><span class="punct">,</span> <span class="symbol">:title</span><span class="punct">],</span> <span class="symbol">:records</span> <span class="punct">=&gt;</span> <span class="attribute">@my_books</span></pre>
<p><span class="constant"><br />
</span></p>
<h2><a href="http://github.com/blythedunham/asset_tag_extensions">Asset Tag Extensions</a></h2>
<pre>script/plugin install git://github.com/blythedunham/javascript_tag_extensions</pre>
<p><img class="alignleft size-thumbnail wp-image-556" title="nuts_sampler" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/08/nuts_sampler-150x150.jpg" alt="nuts_sampler" width="136" height="136" />Your high performance web site client loading slowly? In addition to combining asset files, one of the best ways to improve client load speed is to move the javascript files and inline script tags to <a href="http://developer.yahoo.com/performance/rules.html#page-nav">the bottom of the page</a>. Even better, execute inline javascript after the document loads.  To load files at the bottom of the page use the</p>
<pre class="ruby"><span class="ident">include_javascript_tag</span> <span class="punct">'</span><span class="string">myjsfile</span><span class="punct">',</span> <span class="symbol">:defer</span> <span class="punct">=&gt;</span> <span class="constant">true</span></pre>
<p>Similarly, replacing calls to <tt> javascript_tag</tt> with Asset Tag Extension&#8217;s  <tt>inline_javascript</tt> renders the script at the bottom of the page. Use the <tt> <img src='http://www.snowgiraffe.com/tech/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> n_load =&gt; true</tt> functionality use JQuery OnLoad functionality.</p>
<pre class="ruby">  <span class="punct">&lt;%</span>  <span class="ident">inline_javascript</span> <span class="symbol"> <img src='http://www.snowgiraffe.com/tech/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> n_load</span> <span class="punct">=&gt;</span> <span class="constant">true</span> <span class="keyword">do</span> <span class="punct">%&gt;</span><span class="string">
    alert("I love grapes");</span><span class="punct">
  &lt;%</span> end <span class="punct">%&gt;
</span></pre>
<h2><a href="http://github.com/blythedunham/ruby_prof_request_filters/">Ruby Prof Request Filters</a></h2>
<pre>script/plugin install http://github.com/blythedunham/ruby_prof_request_filters</pre>
<p>Need to instantly profile a page? Output <a href="http://ruby-prof.rubyforge.org/">ruby prof</a> results to your browser by adding the following params to the url: <tt>ruby_prof=true</tt> Flat graphs, html graph, whatever you need, this little tool comes in handy when your solving big problems.</p>
<h2><a href="http://github.com/blythedunham/base4r/">Google Base: Base4r</a></h2>
<p>I did some work on Dan Dukeson&#8217;s <a href="http://code.google.com/apis/base/">Google Base API </a>For Ruby. Add, modify and delete items from Google Base (formerly Froogle) with Ruby.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/545/delectable-plugin-treats-for-the-ruby-shovers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing &#8230; Static Record Cache plugin</title>
		<link>http://www.snowgiraffe.com/tech/338/introducing-static-record-cache-plugin/</link>
		<comments>http://www.snowgiraffe.com/tech/338/introducing-static-record-cache-plugin/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 22:40:57 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[active record context]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[query cache]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[static record cache]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=338</guid>
		<description><![CDATA[Static Record Cache permanently caches active record data for classes which contain small amounts of static data.]]></description>
			<content:encoded><![CDATA[<p>Static Record Cache permanently caches <span class="inline_code">ActiveRecord</span> data for classes which contain small amounts of static data (data that rarely changes). In addition to caching queries on Ids, methods like <span class="inline_code">find_by_name</span> will use cache hits rather than new queries to retrieve data. Static Record Cache is designed to work with or without the built in <a href="http://www.railsenvy.com/2007/3/20/ruby-on-rails-caching-tutorial-part-2#activerecordcaching" target="_blank"> query cache</a>, but by contrast permanently stores the actual record across all contexts and avoids the overhead of instantiating new <span class="inline_code">ActiveRecord</span> objects.</p>
<h2>Install</h2>
<pre>script/plugin install git://github.com/blythedunham/static_record_cache.git</pre>
<h2>Documentation</h2>
<pre class="ruby"><span class="keyword">class </span><span class="class">SomeStaticClass</span> <span class="punct">&lt;</span> <span class="constant">ActiveRecord</span><span class="punct">::</span><span class="constant">Base</span>
  <span class="ident">acts_as_static_record</span>
<span class="keyword">end</span>

<span class="comment">#cache hits</span>
<span class="constant">SomeStaticClass</span><span class="punct">.</span><span class="ident">find_by_name</span><span class="punct">('</span><span class="string">blah</span><span class="punct">')</span>
<span class="constant">SomeStaticClass</span><span class="punct">.</span><span class="ident">find_by_id</span><span class="punct">(</span><span class="number">5</span><span class="punct">)</span>
<span class="constant">SomeStaticClass</span><span class="punct">.</span><span class="ident">find</span> <span class="symbol">:all</span>
<span class="ident">assoc_class</span><span class="punct">.</span><span class="ident">some_static_class</span></pre>
<p>One can specify the cache key for faster lookups and also customize the finder SQL for the class. More documentation can be found in the <a href="http://snowgiraffe.com/rdocs/static_record_cache/">rdocs</a>.</p>
<p><span id="more-338"></span></p>
<p>Another, simpler method of caching can be used by folks using the <a href="http://svn.techno-weenie.net/projects/plugins/active_record_context/README" target="_blank">active record context plugin</a> by technoweenie. Extending <span class="inline_code">StaticRecordCache</span> will permanently cache data for the class regardless of context. This however, only caches by id.</p>
<pre class="ruby"><span class="keyword">class </span><span class="class">TelephoneCarriers</span> <span class="punct">&lt;</span> <span class="constant">ActiveRecord</span><span class="punct">::</span><span class="constant">Base</span>
  <span class="ident">extend</span> <span class="constant">StaticActiveRecordContext</span>
<span class="keyword">end</span></pre>
<p>Be sure to install active_record_cache plugin:</p>
<pre>script/plugin install http://svn.techno-weenie.net/projects/plugins/active_record_context/</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/338/introducing-static-record-cache-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conditional Page Cache</title>
		<link>http://www.snowgiraffe.com/tech/72/conditional-page-cache/</link>
		<comments>http://www.snowgiraffe.com/tech/72/conditional-page-cache/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 08:15:38 +0000</pubDate>
		<dc:creator>blythe</dc:creator>
				<category><![CDATA[Caching]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[action cache]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[page cache]]></category>

		<guid isPermaLink="false">http://www.snowgiraffe.com/tech/?p=72</guid>
		<description><![CDATA[Do to some Obama day drama, I wrote a little plugin that allows you to conditionally page or action cache at runtime. This means that you might page cache depending on the user type, or the date or how you feel when you wake up.
script/plugin install http://arperftoolkit.rubyforge.org/svn/trunk/conditional_page_cache
At the top of the controller, indicate which actions [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="attachment wp-att-79" href="http://www.snowgiraffe.com/tech/?attachment_id=79"><img class="alignright size-thumbnail wp-image-79" title="cash" src="http://www.snowgiraffe.com/tech/wp-content/uploads/2009/01/cash-150x150.jpg" alt="cash" width="104" height="104" /></a>Do to some <a href="http://spongetech.wordpress.com/?p=74">Obama day drama</a>, I wrote a little plugin that allows you to conditionally page or action cache at runtime. This means that you might page cache depending on the user type, or the date or how you feel when you wake up.</p>
<pre style="font-size:10px">script/plugin install http://arperftoolkit.rubyforge.org/svn/trunk/conditional_page_cache</pre>
<p>At the top of the controller, indicate which actions you wish to cache with <span class="inline_code">conditionally_cache</span>.</p>
<pre><span class="keyword">class </span><span class="class">MyController</span> <span class="punct">&lt;</span> <span class="constant">Application</span>

  <span class="ident">conditionally_cache</span> <span class="symbol">:action_one</span><span class="punct">,</span> <span class="symbol">:action_two</span>

  <span class="keyword">def </span><span class="method">cache_page?</span><span class="punct">(</span><span class="ident">current_action_name</span><span class="punct">)</span>
    <span class="attribute">@user</span><span class="punct">.</span><span class="ident">demo?</span>
  <span class="keyword">end</span>

  <span class="keyword">def </span><span class="method">cache_action?</span><span class="punct">(</span><span class="ident">action_name</span><span class="punct">)</span>
    <span class="punct">!</span><span class="attribute">@user</span><span class="punct">.</span><span class="ident">admin?</span>
  <span class="keyword">end</span>

<span class="keyword">end</span></pre>
<p>To use page caching, add a method <span class="inline_code">cache_page?(current_action_name)</span> on the controller.  The page will be cached if this method returns true.</p>
<p>Similarly, return true from method <span class="inline_code">cache_action?(current_action_name)</span> when you want to action cache the page. This method is the same as the one used by the <a href="http://blog.craz8.com/pages/action-cache-plugin">action caching plugin</a> which works great along with this one.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.snowgiraffe.com/tech/72/conditional-page-cache/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>
