<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Eschew Obfuscation: Ruby on Rails Advanced Page Caching</title>
    <link>http://blog.maxdunn.com/articles/2006/09/16/ruby-on-rails-advanced-page-caching</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Max Dunn's Personal Blog</description>
    <item>
      <title>Ruby on Rails Advanced Page Caching</title>
      <description>&lt;p&gt;Ruby on Rails (RoR or Rails) has some cool caching mechanisms already built in. You can cache parts of pages (fragment caching) or whole pages (action caching) while still going into your Rails code to check for permissions or do other things. However, for the highest performance, you can use page caching which serves the web page without even starting Rails, making it incredibly fast. For instance, on my slow computer, doing action caching was 2 times faster than normal, but doing page caching was 30 times faster! (See &lt;a href="http://www.maxdunn.com/typo/articles/2006/09/12/ruby-on-rails-caching-benchmarks"&gt;Ruby on Rails Caching Benchmarks&lt;/a&gt;).&lt;/p&gt;


	&lt;p&gt;However, the problem I ran into was that when you are logged into &lt;a href="http://www.maxdunn.com"&gt;my wiki&lt;/a&gt; as an editor, you see an &amp;#8220;Edit&amp;#8221; link on each section of the page, and if you are logged in as an admin, you see an &amp;#8220;Admin&amp;#8221; choice on the menu. So while the Rails action caching would work fine for this, I couldn&amp;#8217;t use the Rails out-of-the-box page caching since if I was logged in as an Editor and browsed through the pages, the next person that looked at the pages would still see all the &amp;#8220;Edit&amp;#8221; links, even if they were not logged in!&lt;/p&gt;


	&lt;p&gt;After some thought, I came up with two solutions for solving this problem. The first was based on rewriting the &lt;span class="caps"&gt;URL&lt;/span&gt; depending on what role the user is logged in as. I then came up with a better method that relies on setting a cookie with the current role and then using Javascript to modify the page appropriately. Here are the details on both methods.&lt;/p&gt;</description>
      <pubDate>Sat, 16 Sep 2006 13:02:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:6965e239-2b68-4f0a-aa97-427f9eb9575c</guid>
      <author>Max Dunn</author>
      <link>http://blog.maxdunn.com/articles/2006/09/16/ruby-on-rails-advanced-page-caching</link>
      <category>Ruby on Rails</category>
    </item>
    <item>
      <title>"Ruby on Rails Advanced Page Caching" by feedogator</title>
      <description>&lt;p&gt;thanks&lt;/p&gt;</description>
      <pubDate>Wed, 23 Apr 2008 06:09:11 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:416c4708-dfc7-45e5-8f15-6d9450e2240f</guid>
      <link>http://blog.maxdunn.com/articles/2006/09/16/ruby-on-rails-advanced-page-caching#comment-568</link>
    </item>
    <item>
      <title>"Ruby on Rails Advanced Page Caching" by mattc</title>
      <description>&lt;p&gt;we use ajax to handle this.  That way, you can page cache the main page, and use rails for the customized portions that need rails and access to the cookies.  All you need to do is add a onload hook to the body page to load your customized bits&lt;/p&gt;</description>
      <pubDate>Wed, 13 Feb 2008 14:55:35 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:0f819494-e862-4f4b-af79-2cdb0e63417d</guid>
      <link>http://blog.maxdunn.com/articles/2006/09/16/ruby-on-rails-advanced-page-caching#comment-513</link>
    </item>
    <item>
      <title>"Ruby on Rails Advanced Page Caching" by David</title>
      <description>&lt;p&gt;On &lt;a href="http://ror.ru/" rel="nofollow"&gt;ror&lt;/a&gt; have a post about caching web pages.&lt;/p&gt;</description>
      <pubDate>Tue, 13 Nov 2007 14:41:31 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:1ef86b7b-2a12-4e59-9633-312b7eac974f</guid>
      <link>http://blog.maxdunn.com/articles/2006/09/16/ruby-on-rails-advanced-page-caching#comment-369</link>
    </item>
    <item>
      <title>"Ruby on Rails Advanced Page Caching" by Edward</title>
      <description>&lt;p&gt;Hi, I found this interesting because I have &lt;a href="http://www.ethelred.org/articles/2006/10/22/conditional-use-of-page-cache-in-rails" rel="nofollow"&gt;done some work on conditional page cache&lt;/a&gt; use in one of my projects.&lt;/p&gt;


	&lt;p&gt;My method is similar to your second one, but it uses the cookie at the webserver level rather than in javascript, so public users get the cached page and logged in users get a Rails rendered page.&lt;/p&gt;</description>
      <pubDate>Thu, 01 Mar 2007 01:02:24 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:880cddd5-0331-43d5-807d-9841c786a506</guid>
      <link>http://blog.maxdunn.com/articles/2006/09/16/ruby-on-rails-advanced-page-caching#comment-209</link>
    </item>
  </channel>
</rss>
