title: Page Caching, best practice on automatic expires/sweepers
body: <p>I've never really delved into the amazing cache techniques Rails provides until now. One thing that I really can't wrap my head around is how to resolve a this particular problem.</p>
  
  <p>Given that I have a Blog model with many Posts:</p>
  
  <pre><code>class Blog &lt; ActiveRecord::Base
    has_many :posts
  end
  
  class Post &lt; ActiveRecord::Base
    named_scope :published, :conditions =&gt; ["published_at &lt; ?", Time.now]
  end
  </code></pre>
  
  <p>And the show action in the BlogsController shows a list of Posts that have been published:</p>
  
  <pre><code>// BlogsController
  
  def show
   @blog = Blog.find(params[:id)
  end
  
  // View
  
  &lt;% @blog.posts.published.each do |p| %&gt;
   &lt;h2&gt;&lt;%=h p.title %&gt;&lt;/h2&gt;
   &lt;%= simple_format(p.content) %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>The cache has to expire when any change is done to the published_at attribute BUT it also need to do it when published_at is put in the future and that time is reached.</p>
  
  <p>Can you guys throw me some ideas and pointers of how to best solve this? Cron-job or am I loosing my mind?</p>