Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Bust caches before your users do
tree: bf8728a056

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
rails
spec
tasks
.gitignore
MIT-LICENSE
README.markdown
Rakefile
init.rb
require.rb

README.markdown

BackgroundCache

Bust caches before your users do (in your Rails app).

Requirements

sudo gem install background_cache

config/environment.rb

config.gem 'background_cache'

Dynamic Configuration

Create lib/background_cache_config.rb:

BackgroundCache::Config.new do

  # Configure a background cache in one call
  
  Tag::League.find(:all).each do |tag|
    cache(
      # Route params
      :controller => 'sections',
      :action => 'teams',
      :tag => tag.permalink,
      
      # Background cache options
      :group => 'every_hour',
      :layout => false,
      :only => "sections_teams_#{tag.permalink}"
    )
  end
  
  # Configure using block methods
  
  group('every_hour').layout(false).only("sections_teams_#{tag.permalink}") do
    Tag::League.find(:all).each do |tag|
      cache("/#{tag.permalink}")
    end
  end
end

The cache method takes route parameters or a path.

The only and except methods/options take fragment ids or arrays of fragment ids.

If no fragment is specified, all of the action's caches will regenerate.

Rake task

Add rake background_cache to cron. All cache configurations are busted every time it is run.

To run a specific group of caches, run rake background_cache[every_hour] (as per the example above).

Something went wrong with that request. Please try again.