title: Caching/Etag for Static Action in Rails 4
body: <p>Since Rails 4 removed page caching and action caching, I'm wondering what is the Rails 4 way to cache an action that has no variables and has only html in the view? Should I fragment cache the static html in the view? How do I set an etag/fresh_when when there is no model to set it to expire with? I'm struggling to find an example or convention to caching what should be the easiest page to cache.</p>
  
  <p>One note is that while the view is completely static, the page still has a dynamic navbar depending on whether the user is signed in or not. How would you handle a static page like this without resorting to action caching since its been removed and the convention has been set not to use the gem version?</p>
  
  <p>Example:</p>
  
  <pre><code>class HomesController &lt; ApplicationController    
    def index
    end
  end
  </code></pre>
  
  <p>homes/index.html.erb</p>
  
  <pre><code>&lt;div&gt;A bunch of normal html tags with no erb&lt;/div&gt;
  </code></pre>
  
  <p><strong>Edit:</strong>
  Based on @severin's answer and my own research, here is what I have come up with so far.</p>
  
  <pre><code>class HomesController &lt; ApplicationController    
    def index
      fresh_when(["some-identifier", current_user, flash])
    end
  end
  </code></pre>
  
  <p>In addition, I'm using <a href="https://github.com/n8/bust_rails_etags" rel="noreferrer">https://github.com/n8/bust_rails_etags</a> to reset all etags after a deploy because the view may have changed between deploys. I think this covers the etag fairly well although I'm still curious whether fresh when will include some identifier about the view automatically and whether "some-idnetifier" is necessary? Is it going to be a problem that sometimes current_user and flash will be nil?</p>
  
  <p>Now on the second point of fragment caching the static content. I'm assuming if I did:</p>
  
  <pre><code>cache "v1" do
    all my html
  end
  </code></pre>
  
  <p>I'd have to remember to always change the cache identifier when the page is changed otherwise my app would serve stale content. Any way to automate this as well or is already handled by rails? It would be nice to just cache the last time the view was updated or something clever so I don't have to keep track on when my static content is changed.</p>