title: pagination and memcached in rails
body: <p>What's the best way to cache a paginated result set with rails and memcached?</p>
  
  <p>For example, <strong>posts controller</strong>:</p>
  
  <pre><code>def index
    @posts = Rails.cache.fetch('all_posts') do
      Post.paginate(:conditions =&gt; ['xx = ?', yy], :include =&gt; [:author], :page =&gt; params[:page], :order =&gt; 'created_at DESC')
    end
  end
  </code></pre>
  
  <p>This obviously doesn't work when the <code>params[:page]</code> changes. I can change the key to <code>"all_posts_#{params[:page]}_#{params[:order]_#{last_record.created_at.to_i}"</code>, but then there could be several possible orders (recent, popular, most voted etc) and there will be a combination of pages and orders ... lots of keys this way.</p>
  
  <p>Problem #2 - It seems that when I implement this solution, the caches get written correctly and the page loads fine during the first call to a paginated action. When I click back on the same page i.e. page1, with <code>recent</code> order, it seems the browser does not even make a call to the server. I don't see any controller action being called in the production log.</p>
  
  <p>I am using passenger, REE, memcached, and rails 2.3.5. Firebug shows no requests being made....</p>
  
  <p>Is there a simples/more graceful way of handling this?</p>