title: rails fresh_when/stale? usage
body: <p>In my post_index action, I generate different kinds of "@posts" like..</p>
  
  <pre><code>def index
    case params[:listing_type]
      when "all"
        @posts = get_all_post_from_memcached
      when "most_popular"
        @posts = get_all_most_popular_from_memcached
  
        respond_to do |format|
          format.html
          format.js #for ajax reqeusts
          format.xml #for rss etc
        end
    end
  end
  
  ##updated
  def index
    case params[:listing_type]
      when "all"
        #the key here is teh same key I used for memcached   
        if stale?(:etag =&gt; 'all_posts_key')
          @posts = get_all_post_from_memcached
        else
          head :not_modified and return
        end
      when "most_popular"
        if stale?(:etag =&gt; 'most_popular_key')
          @posts = get_all_most_popular_from_memcached
        else
          head :notified and return
        end
        respond_to do |format|
          format.html
          format.js #for ajax reqeusts
          format.xml #for rss etc
        end
    end
  end
  </code></pre>
  
  <p>From what I understand <code>fresh_when</code> takes a <code>etag</code>, and it is to be used if there is no difference in different kinds of rendered (in my case the rendering is different based on html or ajax) </p>
  
  <p>and </p>
  
  <p><code>stale?</code> also takes an  <code>etag</code> and surrounds the respond_to block.</p>
  
  <p>In this case the <code>etag</code> will be different based on the different listing types. But it seems there isn't much flexibility in the way <code>fresh_when</code> or <code>stale?</code> can be used here?</p>
  
  <p>Thanks</p>
  
  <p>update. I changed the original block a little and now  get a double render error what am I doing wrong, should "head :notified and return" just return the header and not touch the <code>respond_to</code> block?</p>