Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 81 lines (53 sloc) 2.005 kB
346898f @winton First commit using gem_template
authored
1 BackgroundCache
2 ===============
4ab38af @winton [gem_template] First commit
authored
3
3bcf819 @winton README
authored
4 Bust caches before your users do (in your Rails app).
ff08ea2 @winton README, gem description
authored
5
2ca2e42 @winton README
authored
6 Works with [memcache-client](https://github.com/mperham/memcache-client), [Dalli](https://github.com/mperham/dalli), or [memcached](https://github.com/fauna/memcached).
7
ff08ea2 @winton README, gem description
authored
8 Requirements
9 ------------
10
0cc22ee @winton Daemon/client working, untested
authored
11 gem install background_cache
4ab38af @winton [gem_template] First commit
authored
12
346898f @winton First commit using gem_template
authored
13 Dynamic Configuration
14 ---------------------
15
140778d @winton README
authored
16 Create `lib/background_cache_config.rb` in your Rails app:
4ab38af @winton [gem_template] First commit
authored
17
0cc22ee @winton Daemon/client working, untested
authored
18 BackgroundCache::Config.new do
346898f @winton First commit using gem_template
authored
19
0cc22ee @winton Daemon/client working, untested
authored
20 # Configure using block methods
3bcf819 @winton README
authored
21
0cc22ee @winton Daemon/client working, untested
authored
22 group('every_hour').layout(false).only("sections_teams_#{tag.permalink}") do
23 Tag::League.find(:all).each do |tag|
24 cache(:path => "/#{tag.permalink}")
25 end
26 end
27
28 # Configure using options
29
30 Tag::League.find(:all).each do |tag|
31 cache(
32 # Route params
33 :controller => 'sections',
34 :action => 'teams',
35 :tag => tag.permalink,
4ab38af @winton [gem_template] First commit
authored
36
0cc22ee @winton Daemon/client working, untested
authored
37 # Or specify a path
38 :path => "/#{tag.permalink}",
39
40 # Background cache options
41 :group => 'every_hour',
42 :layout => false,
43 :only => "sections_teams_#{tag.permalink}"
44 )
45 end
46 end
4ab38af @winton [gem_template] First commit
authored
47
0cc22ee @winton Daemon/client working, untested
authored
48 The `only` and `except` options take cache fragment ids or arrays of cache fragment ids.
085cb14 @winton [gem_template] Updating README
authored
49
3bcf819 @winton README
authored
50 If no fragment is specified, all of the action's caches will regenerate.
085cb14 @winton [gem_template] Updating README
authored
51
0cc22ee @winton Daemon/client working, untested
authored
52 Rake Task
346898f @winton First commit using gem_template
authored
53 ---------
085cb14 @winton [gem_template] Updating README
authored
54
0cc22ee @winton Daemon/client working, untested
authored
55 Add `rake background_cache` to cron. All cache configurations are busted every time it is run.
56
8bba43b @winton README
authored
57 To run a specific group of caches, run `rake background_cache[every_hour]` (as per the example above).
0cc22ee @winton Daemon/client working, untested
authored
58
59 Daemon Mode
60 -----------
61
62 Create `config/background_cache.yml` in your Rails app:
63
64 redis: localhost:6379/0
65
66 Start a `background_cache` daemon from your Rails app:
67
68 $ cd path/to/app
69 $ background_cache
70
71 Run caches via Ruby:
72
73 require 'background_cache'
74
331759d @winton README
authored
75 client = BackgroundCache::Client.new('/path/to/app')
0cc22ee @winton Daemon/client working, untested
authored
76
77 # Cache group
331759d @winton README
authored
78 client.cache(:group => "every_hour")
085cb14 @winton [gem_template] Updating README
authored
79
0cc22ee @winton Daemon/client working, untested
authored
80 # Manual cache
81 client.cache(:path => "/")
Something went wrong with that request. Please try again.