Changeset 1646

Show
Ignore:
Timestamp:
02/23/08 11:40:27 (3 months ago)
Author:
pdcawley
Message:

Hah! Take that you lousy cache monster!

We no longer attempt to sweep the cache 99 times per request when
changing blog settings. All the cache deletions are saved up until
the end of the request so if BlogSweeper#expire_for? gets called
multiple times, the cache still only gets swept once.

Which is nice.

I've turned caching on in the development environment for the time
being too - I want the debug level logging, and I want to hit problems
quickly when I'm testing rather than discovering them in a production
log.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/models/blog_sweeper.rb

    r1629 r1646  
    11class BlogSweeper < ActionController::Caching::Sweeper 
    22  observe Category, Blog, Sidebar, User, Article, Page, Categorization 
     3 
     4  def pending_sweeps 
     5    @pending_sweeps ||= Set.new 
     6  end 
     7 
     8  def run_pending_page_sweeps 
     9    logger.debug "Running pending page_sweeps: #{pending_sweeps.to_a.inspect}" 
     10    pending_sweeps.each do |each| 
     11      self.send(each) 
     12    end 
     13  end 
    314 
    415  def after_comments_create 
     
    4051    case record 
    4152    when Page 
    42       sweep_pages(record) 
     53      pending_sweeps << :sweep_pages 
    4354    when Content 
    4455      if record.invalidates_cache?(destroying) 
    45         sweep_articles 
    46         sweep_pages 
     56        pending_sweeps << :sweep_articles << :sweep_pages 
    4757      end 
    4858    when Sidebar, Category, Categorization 
    49       sweep_articles 
    50       sweep_pages 
     59      pending_sweeps << :sweep_articles << :sweep_pages 
    5160    when Blog, User 
    52       sweep_all 
    53       sweep_theme 
     61      pending_sweeps << :sweep_all << :sweep_theme 
     62    end 
     63    unless controller 
     64      run_pending_page_sweeps 
    5465    end 
    5566  end 
    5667 
    5768  def sweep_all 
     69    PageCache.sweep_all 
    5870    expire_fragment(/.*/) 
    59     PageCache.sweep_all 
    6071  end 
    6172 
     
    7283  end 
    7384 
    74   def sweep_pages(record = nil) 
     85  def sweep_pages 
    7586    expire_fragment(/.*\/pages\/.*/) 
    7687    expire_fragment(/.*\/view_page.*/) 
     
    8394    @logger ||= RAILS_DEFAULT_LOGGER || Logger.new(STDERR) 
    8495  end 
     96 
     97  private 
     98  def callback(timing) 
     99    super 
     100    if timing == :after 
     101      run_pending_page_sweeps 
     102    end 
     103  end 
    85104end 
  • trunk/app/models/page_cache.rb

    r1629 r1646  
    55 
    66  def self.sweep_all 
    7     logger.debug "PageCache - sweep_all called
     7    logger.debug "PageCache - sweep_all called by #{caller[1].inspect}
    88    unless Blog.default && Blog.default.cache_option == "caches_action_with_params" 
    99      self.zap_pages('index.*', 'articles.*', 'articles', 'pages', 
     
    1616 
    1717  def self.sweep_theme_cache 
    18     logger.debug "PageCache - sweep_theme_cache called
     18    logger.debug "PageCache - sweep_theme_cache called by #{caller[1].inspect}
    1919    self.zap_pages('images/theme', 'stylesheets/theme', 'javascripts/theme') 
    2020  end 
  • trunk/config/environments/development.rb

    r1615 r1646  
    99# Show full error reports and disable caching 
    1010config.action_controller.consider_all_requests_local = true 
    11 config.action_controller.perform_caching             = fals
     11config.action_controller.perform_caching             = tru
    1212 
    1313# Don't care if the mailer can't send 
    1414config.action_mailer.raise_delivery_errors = false 
     15 
     16def log_to(stream) 
     17  ActiveRecord::Base.logger = Logger.new(stream) 
     18  ActiveRecord::Base.clear_active_connections! 
     19end