<?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; page cache</title>
	<atom:link href="http://www.snowgiraffe.com/tech/tag/page-cache/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>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>
	</channel>
</rss>
