No commit activity in last 3 years
No release in over 3 years
Bust caches before your users do.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 2.3.10
~> 1.0

Runtime

 Project Readme

BackgroundCache

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

Works with memcache-client, Dalli, or memcached.

Requirements

gem install background_cache

Dynamic Configuration

Create lib/background_cache_config.rb in your Rails app:

BackgroundCache::Config.new do

  # Configure using block methods
  
  group('every_hour').layout(false).only("sections_teams_#{tag.permalink}") do
    Tag::League.find(:all).each do |tag|
      cache(:path => "/#{tag.permalink}")
    end
  end

  # Configure using options
  
  Tag::League.find(:all).each do |tag|
    cache(
      # Route params
      :controller => 'sections',
      :action => 'teams',
      :tag => tag.permalink,

      # Or specify a path
      :path => "/#{tag.permalink}",
      
      # Background cache options
      :group => 'every_hour',
      :layout => false,
      :only => "sections_teams_#{tag.permalink}"
    )
  end
end

The only and except options take cache fragment ids or arrays of cache 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).

Daemon Mode

Create config/background_cache.yml in your Rails app:

redis: localhost:6379/0

Start a background_cache daemon from your Rails app:

$ cd path/to/app
$ background_cache

Run caches via Ruby:

require 'background_cache'

client = BackgroundCache::Client.new('/path/to/app')

# Cache group
client.cache(:group => "every_hour")

# Manual cache
client.cache(:path => "/")