<?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; query cache</title>
	<atom:link href="http://www.snowgiraffe.com/tech/tag/query-cache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.snowgiraffe.com/tech</link>
	<description>rails, rubies, and sometimes dolphins</description>
	<lastBuildDate>Mon, 17 Oct 2011 17:45:19 +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>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>
	</channel>
</rss>

