lacquer 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
1
+ *.gem
2
+ .bundle
3
+ .DS_Store
4
+ Gemfile.lock
5
+ pkg/*
data/README.rdoc CHANGED
@@ -1,202 +1,214 @@
1
- = lacquer
2
-
3
- Rails drop in for Varnish support.
4
-
5
- == Install
6
- This gem requires ruby 1.9
7
-
8
- Basic installation
9
-
10
- sudo gem install lacquer
11
- rails generate lacquer:install
12
-
13
- config/initializers/lacquer.rb
14
-
15
- Lacquer.configure do |config|
16
- # Globally enable/disable cache
17
- config.enable_cache = true
18
-
19
- # Unless overridden in a controller or action, the default will be used
20
- config.default_ttl = 1.week
21
-
22
- # Can be :none, :delayed_job, :resque
23
- config.job_backend = :none
24
-
25
- # Array of Varnish servers to manage
26
- config.varnish_servers << {
27
- :host => "0.0.0.0", :port => 6082 # if you have authentication enabled, add :secret => "your secret"
28
- }
29
-
30
- # Number of retries
31
- config.retries = 5
32
-
33
- # config handler (optional, if you use Hoptoad or another error tracking service)
34
- config.command_error_handler = lambda { |s| HoptoadNotifier.notify(s) }
35
- end
36
-
37
- app/controllers/application_controller.rb
38
-
39
- class ApplicationController < ActionController::Base
40
- include Lacquer::CacheUtils
41
- end
42
-
43
- config/varnishd.yml
44
-
45
- development:
46
- listen: localhost:3001
47
- telnet: localhost:6082
48
- sbin_path: /usr/local/sbin
49
- storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
50
-
51
- test:
52
- listen: localhost:3002
53
- telnet: localhost:6083
54
- sbin_path: /usr/local/sbin
55
- storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
56
-
57
- production:
58
- listen: :80
59
- telnet: localhost:6082
60
- sbin_path: /usr/local/sbin
61
- storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
62
- params:
63
- overflow_max: 2000
64
- thread_pool_add_delay: 2
65
- thread_pools: 4 # <Number of cpu cores>
66
- thread_pool_min: 200 # <800/number of cpu cores>
67
- thread_pool_max: 4000
68
-
69
- If only some urls of the application should be cached by varnish, Lacquer::CacheControl will be helpful.
70
-
71
- config/initializers/caches.rb
72
-
73
- require "lacquer/cache_control"
74
-
75
- Lacquer.cache_control.configure do |config|
76
- config.register :static, :url => "^/images",
77
- :expires_in => "365d"
78
-
79
- config.register :static, :url => "^/stylesheets",
80
- :expires_in => "365d"
81
-
82
- config.register :static, :url => "^/javascripts",
83
- :expires_in => "365d"
84
-
85
- config.register :class_section, :url => "^(/[a-z]{2})?/(info_screens|class_sections)/%s.*$",
86
- :args => "[0-9]+",
87
- :expires_in => "1m"
88
-
89
- config.register :open_scoring, :url => "^(/[a-z]{2})?/class_sections/%s/open_scoring.*$",
90
- :args => "[0-9]+",
91
- :expires_in => "1m"
92
-
93
- end
94
-
95
- In the sweeper we can do something like this
96
-
97
- class_section = ClassSection.find(1)
98
- Lacquer.cache_control.purge(:open_scoring, class_section)
99
-
100
- This will purge "^(/[a-z]{2})?/class_sections/1/open_scoring.*$" (/sv/class_sections/1/open_scoring.js, /sv/class_sections/1/open_scoring.html)
101
-
102
- The varnish.vcl is preprocssed when starting varnishd with the rake tasks
103
-
104
- rake varnishd:start
105
-
106
- config/varnish.vcl.erb
107
-
108
- sub vcl_recv {
109
- # Lookup requests that we know should be cached
110
- if (<%= Lacquer.cache_control.to_vcl_conditions %>) {
111
- # Clear cookie and authorization headers, set grace time, lookup in the cache
112
- unset req.http.Cookie;
113
- unset req.http.Authorization;
114
- return(lookup);
115
- }
116
-
117
- # Generates
118
- #
119
- # if(req.url ~ "^/images" ||
120
- # req.url ~ "^/stylesheets" ||
121
- # req.url ~ "^/javascripts" ||
122
- # req.url ~ "^(/[a-z]{2})?/(info_screens|class_sections)/[0-9]+.*$" ||
123
- # req.url ~ "^(/[a-z]{2})?/class_sections/[0-9]+/open_scoring.*$") {
124
- # unset req.http.Cookie;
125
- # unset req.http.Authorization;
126
- # return(lookup);
127
- # }
128
- }
129
-
130
- sub vcl_fetch {
131
- <%= Lacquer.cache_control.to_vcl_override_ttl_urls %>
132
-
133
- # Generates
134
- #
135
- # if(req.url ~ "^/images" || req.url ~ "^/stylesheets" || req.url ~ "^/javascripts") {
136
- # unset beresp.http.Set-Cookie;
137
- # set beresp.ttl = 365d;
138
- # return(deliver);
139
- # }
140
- #
141
- # if(req.url ~ "^(/[a-z]{2})?/(info_screens|class_sections)/[0-9]+.*$" ||
142
- # req.url ~ "^(/[a-z]{2})?/class_sections/[0-9]+/open_scoring.*$") {
143
- # unset beresp.http.Set-Cookie;
144
- # set beresp.ttl = 1m;
145
- # return(deliver);
146
- # }
147
- }
148
-
149
- This makes it much simpler to perform cacheing, it's only setuped in one place, purge it or just let it expire.
150
-
151
- == Usage
152
-
153
- To set a custom ttl for a controller:
154
-
155
- before_filter { |controller| controller.set_cache_ttl(15.minutes) }
156
-
157
- Clearing the cache:
158
-
159
- class Posts < ApplicationController
160
- after_filter :clear_cache, :only => [ :create, :update, :destroy ]
161
-
162
- private
163
-
164
- def clear_cache
165
- clear_cache_for(
166
- root_path,
167
- posts_path,
168
- post_path(@post))
169
- end
170
- end
171
-
172
- Control varnishd with the following rake tasks
173
-
174
- rake varnishd:start
175
- rake varnishd:stop
176
- rake varnishd:restart
177
- rake varnishd:status
178
- rake varnishd:global_purge
179
-
180
- == Gotchas
181
-
182
- The default TTL for most actions is set to 0, since for most cases you'll probably want to be fairly explicit about what pages do get cached by varnish. The default cache header is typically:
183
-
184
- Cache-Control: max-age=0, no-cache, private
185
-
186
- This is good for normal controller actions, since you won't want to cache them. If TTL for an action is set to 0, it won't mess with the default header.
187
-
188
- The key gotcha here is that cached pages strip cookies, so if your application relies on sessions and uses authenticity tokens, the user will need a session cookie set before form actions will work. Setting default TTL to 0 here will make sure these session cookies won't break.
189
-
190
- As a result, all you have to do to set a cacheable action is the before filter above.
191
-
192
- == Note on Patches/Pull Requests
193
-
194
- * Fork the project.
195
- * Make your feature addition or bug fix.
196
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
197
- * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
198
- * Send me a pull request. Bonus points for topic branches.
199
-
200
- == Copyright
201
-
202
- Copyright (c) 2010 Russ Smith. See LICENSE for details.
1
+ = lacquer
2
+
3
+ Rails drop in for Varnish support.
4
+
5
+ == Install
6
+ This gem requires ruby 1.9
7
+
8
+ Basic installation
9
+
10
+ sudo gem install lacquer
11
+ rails generate lacquer:install
12
+
13
+ config/initializers/lacquer.rb
14
+
15
+ Lacquer.configure do |config|
16
+ # Globally enable/disable cache
17
+ config.enable_cache = true
18
+
19
+ # Unless overridden in a controller or action, the default will be used
20
+ config.default_ttl = 1.week
21
+
22
+ # Can be :none, :delayed_job, :resque
23
+ config.job_backend = :none
24
+
25
+ # Array of Varnish servers to manage
26
+ config.varnish_servers << {
27
+ :host => "0.0.0.0", :port => 6082 # if you have authentication enabled, add :secret => "your secret"
28
+ }
29
+
30
+ # Number of retries
31
+ config.retries = 5
32
+
33
+ # config handler (optional, if you use Hoptoad or another error tracking service)
34
+ config.command_error_handler = lambda { |s| HoptoadNotifier.notify(s) }
35
+
36
+
37
+ ### Varnish - 2.x / 3.x .. VCL-Changes
38
+ ### https://www.varnish-cache.org/docs/trunk/installation/upgrade.html
39
+
40
+ # => Purge Command ( "url.purge" for Varnish 2.x .. "ban.url" for Varnish 3.x )
41
+ # => purges are now called bans in Varnish 3.x .. purge() and purge_url() are now respectively ban() and ban_url()
42
+ config.purge_command = "ban.url"
43
+
44
+ # => VCL_Fetch Pass Command ( "pass" for Varnish 2.x .. "hit_for_pass" for Varnish 3.x )
45
+ # => pass in vcl_fetch renamed to hit_for_pass in Varnish 3.x
46
+ config.vcl_pass_command = "pass"
47
+ end
48
+
49
+ app/controllers/application_controller.rb
50
+
51
+ class ApplicationController < ActionController::Base
52
+ include Lacquer::CacheUtils
53
+ end
54
+
55
+ config/varnishd.yml
56
+
57
+ development:
58
+ listen: localhost:3001
59
+ telnet: localhost:6082
60
+ sbin_path: /usr/local/sbin
61
+ storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
62
+
63
+ test:
64
+ listen: localhost:3002
65
+ telnet: localhost:6083
66
+ sbin_path: /usr/local/sbin
67
+ storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
68
+
69
+ production:
70
+ listen: :80
71
+ telnet: localhost:6082
72
+ sbin_path: /usr/local/sbin
73
+ storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
74
+ params:
75
+ overflow_max: 2000 # for Varnish 2.x ... use "queue_max: 2000" for Varnish 3.x
76
+ thread_pool_add_delay: 2
77
+ thread_pools: 4 # <Number of cpu cores>
78
+ thread_pool_min: 200 # <800/number of cpu cores>
79
+ thread_pool_max: 4000
80
+
81
+ If only some urls of the application should be cached by varnish, Lacquer::CacheControl will be helpful.
82
+
83
+ config/initializers/caches.rb
84
+
85
+ require "lacquer/cache_control"
86
+
87
+ Lacquer.cache_control.configure do |config|
88
+ config.register :static, :url => "^/images",
89
+ :expires_in => "365d"
90
+
91
+ config.register :static, :url => "^/stylesheets",
92
+ :expires_in => "365d"
93
+
94
+ config.register :static, :url => "^/javascripts",
95
+ :expires_in => "365d"
96
+
97
+ config.register :class_section, :url => "^(/[a-z]{2})?/(info_screens|class_sections)/%s.*$",
98
+ :args => "[0-9]+",
99
+ :expires_in => "1m"
100
+
101
+ config.register :open_scoring, :url => "^(/[a-z]{2})?/class_sections/%s/open_scoring.*$",
102
+ :args => "[0-9]+",
103
+ :expires_in => "1m"
104
+
105
+ end
106
+
107
+ In the sweeper we can do something like this
108
+
109
+ class_section = ClassSection.find(1)
110
+ Lacquer.cache_control.purge(:open_scoring, class_section)
111
+
112
+ This will purge "^(/[a-z]{2})?/class_sections/1/open_scoring.*$" (/sv/class_sections/1/open_scoring.js, /sv/class_sections/1/open_scoring.html)
113
+
114
+ The varnish.vcl is preprocssed when starting varnishd with the rake tasks
115
+
116
+ rake lacquer:varnishd:start
117
+
118
+ config/varnish.vcl.erb
119
+
120
+ sub vcl_recv {
121
+ # Lookup requests that we know should be cached
122
+ if (<%= Lacquer.cache_control.to_vcl_conditions %>) {
123
+ # Clear cookie and authorization headers, set grace time, lookup in the cache
124
+ unset req.http.Cookie;
125
+ unset req.http.Authorization;
126
+ return(lookup);
127
+ }
128
+
129
+ # Generates
130
+ #
131
+ # if(req.url ~ "^/images" ||
132
+ # req.url ~ "^/stylesheets" ||
133
+ # req.url ~ "^/javascripts" ||
134
+ # req.url ~ "^(/[a-z]{2})?/(info_screens|class_sections)/[0-9]+.*$" ||
135
+ # req.url ~ "^(/[a-z]{2})?/class_sections/[0-9]+/open_scoring.*$") {
136
+ # unset req.http.Cookie;
137
+ # unset req.http.Authorization;
138
+ # return(lookup);
139
+ # }
140
+ }
141
+
142
+ sub vcl_fetch {
143
+ <%= Lacquer.cache_control.to_vcl_override_ttl_urls %>
144
+
145
+ # Generates
146
+ #
147
+ # if(req.url ~ "^/images" || req.url ~ "^/stylesheets" || req.url ~ "^/javascripts") {
148
+ # unset beresp.http.Set-Cookie;
149
+ # set beresp.ttl = 365d;
150
+ # return(deliver);
151
+ # }
152
+ #
153
+ # if(req.url ~ "^(/[a-z]{2})?/(info_screens|class_sections)/[0-9]+.*$" ||
154
+ # req.url ~ "^(/[a-z]{2})?/class_sections/[0-9]+/open_scoring.*$") {
155
+ # unset beresp.http.Set-Cookie;
156
+ # set beresp.ttl = 1m;
157
+ # return(deliver);
158
+ # }
159
+ }
160
+
161
+ This makes it much simpler to perform cacheing, it's only setuped in one place, purge it or just let it expire.
162
+
163
+ == Usage
164
+
165
+ To set a custom ttl for a controller:
166
+
167
+ before_filter { |controller| controller.set_cache_ttl(15.minutes) }
168
+
169
+ Clearing the cache:
170
+
171
+ class Posts < ApplicationController
172
+ after_filter :clear_cache, :only => [ :create, :update, :destroy ]
173
+
174
+ private
175
+
176
+ def clear_cache
177
+ clear_cache_for(
178
+ root_path,
179
+ posts_path,
180
+ post_path(@post))
181
+ end
182
+ end
183
+
184
+ Control varnishd with the following rake tasks
185
+
186
+ rake lacquer:varnishd:start
187
+ rake lacquer:varnishd:stop
188
+ rake lacquer:varnishd:restart
189
+ rake lacquer:varnishd:status
190
+ rake lacquer:varnishd:global_purge
191
+
192
+ == Gotchas
193
+
194
+ The default TTL for most actions is set to 0, since for most cases you'll probably want to be fairly explicit about what pages do get cached by varnish. The default cache header is typically:
195
+
196
+ Cache-Control: max-age=0, no-cache, private
197
+
198
+ This is good for normal controller actions, since you won't want to cache them. If TTL for an action is set to 0, it won't mess with the default header.
199
+
200
+ The key gotcha here is that cached pages strip cookies, so if your application relies on sessions and uses authenticity tokens, the user will need a session cookie set before form actions will work. Setting default TTL to 0 here will make sure these session cookies won't break.
201
+
202
+ As a result, all you have to do to set a cacheable action is the before filter above.
203
+
204
+ == Note on Patches/Pull Requests
205
+
206
+ * Fork the project.
207
+ * Make your feature addition or bug fix.
208
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
209
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
210
+ * Send me a pull request. Bonus points for topic branches.
211
+
212
+ == Copyright
213
+
214
+ Copyright (c) 2010 Russ Smith. See LICENSE for details.
@@ -1,21 +1,33 @@
1
- Lacquer.configure do |config|
2
- # Globally enable/disable cache
3
- config.enable_cache = true
4
-
5
- # Unless overridden in a controller or action, the default will be used
6
- config.default_ttl = 1.week
7
-
8
- # Can be :none, :delayed_job, :resque
9
- config.job_backend = :none
10
-
11
- # Array of Varnish servers to manage
12
- config.varnish_servers << {
13
- :host => "0.0.0.0", :port => 6082 # if you have authentication enabled, add :secret => "your secret"
14
- }
15
-
16
- # Number of retries
17
- config.retries = 5
18
-
19
- # Config handler (optional, if you use Hoptoad or another error tracking service)
20
- config.command_error_handler = lambda { |s| HoptoadNotifier.notify(s) }
21
- end
1
+ Lacquer.configure do |config|
2
+ # Globally enable/disable cache
3
+ config.enable_cache = true
4
+
5
+ # Unless overridden in a controller or action, the default will be used
6
+ config.default_ttl = 1.week
7
+
8
+ # Can be :none, :delayed_job, :resque
9
+ config.job_backend = :none
10
+
11
+ # Array of Varnish servers to manage
12
+ config.varnish_servers << {
13
+ :host => "0.0.0.0", :port => 6082 # if you have authentication enabled, add :secret => "your secret"
14
+ }
15
+
16
+ # Number of retries
17
+ config.retries = 5
18
+
19
+ # Config handler (optional, if you use Hoptoad or another error tracking service)
20
+ # config.command_error_handler = lambda { |s| HoptoadNotifier.notify(s) }
21
+
22
+
23
+ ### Varnish - 2.x / 3.x .. VCL-Changes
24
+ ### https://www.varnish-cache.org/docs/trunk/installation/upgrade.html
25
+
26
+ # => Purge Command ( "url.purge" for Varnish 2.x .. "ban.url" for Varnish 3.x )
27
+ # => purges are now called bans in Varnish 3.x .. purge() and purge_url() are now respectively ban() and ban_url()
28
+ config.purge_command = "url.purge"
29
+
30
+ # => VCL_Fetch Pass Command ( "pass" for Varnish 2.x .. "hit_for_pass" for Varnish 3.x )
31
+ # => pass in vcl_fetch renamed to hit_for_pass in Varnish 3.x
32
+ config.pass_command = "pass"
33
+ end
@@ -1,102 +1,102 @@
1
- backend default {
2
- .host = "<%= backend.split(':').first %>";
3
- .port = "<%= backend.split(':').last %>";
4
- }
5
-
6
- # Handling of requests that are received from clients.
7
- # First decide whether or not to lookup data in the cache.
8
- sub vcl_recv {
9
- # Pipe requests that are non-RFC2616 or CONNECT which is weird.
10
- if (req.request != "GET" &&
11
- req.request != "HEAD" &&
12
- req.request != "PUT" &&
13
- req.request != "POST" &&
14
- req.request != "TRACE" &&
15
- req.request != "OPTIONS" &&
16
- req.request != "DELETE") {
17
- return(pipe);
18
- }
19
-
20
- if (req.backend.healthy) {
21
- set req.grace = 30s;
22
- } else {
23
- set req.grace = 1h;
24
- }
25
-
26
- # Pass requests that are not GET or HEAD
27
- if (req.request != "GET" && req.request != "HEAD") {
28
- return(pass);
29
- }
30
-
31
- # Handle compression correctly. Varnish treats headers literally, not
32
- # semantically. So it is very well possible that there are cache misses
33
- # because the headers sent by different browsers aren't the same.
34
- # @see: http://varnish.projects.linpro.no/wiki/FAQ/Compression
35
- if (req.http.Accept-Encoding) {
36
- if (req.http.Accept-Encoding ~ "gzip") {
37
- # if the browser supports it, we'll use gzip
38
- set req.http.Accept-Encoding = "gzip";
39
- } elsif (req.http.Accept-Encoding ~ "deflate") {
40
- # next, try deflate if it is supported
41
- set req.http.Accept-Encoding = "deflate";
42
- } else {
43
- # unknown algorithm. Probably junk, remove it
44
- remove req.http.Accept-Encoding;
45
- }
46
- }
47
-
48
- # Clear cookie and authorization headers, set grace time, lookup in the cache
49
- unset req.http.Cookie;
50
- unset req.http.Authorization;
51
- return(lookup);
52
- }
53
-
54
- # Called when entering pipe mode
55
- sub vcl_pipe {
56
- # If we don't set the Connection: close header, any following
57
- # requests from the client will also be piped through and
58
- # left untouched by varnish. We don't want that.
59
- set req.http.connection = "close";
60
- return(pipe);
61
- }
62
-
63
- # Called when the requested object has been retrieved from the
64
- # backend, or the request to the backend has failed
65
- sub vcl_fetch {
66
- # Set the grace time
67
- set beresp.grace = 1h;
68
-
69
- # Do not cache the object if the status is not in the 200s
70
- if (beresp.status >= 300) {
71
- # Remove the Set-Cookie header
72
- remove beresp.http.Set-Cookie;
73
- return(pass);
74
- }
75
-
76
- # Do not cache the object if the backend application does not want us to.
77
- if (beresp.http.Cache-Control ~ "(no-cache|no-store|private|must-revalidate)") {
78
- return(pass);
79
- }
80
-
81
- # Everything below here should be cached
82
-
83
- # Remove the Set-Cookie header
84
- remove beresp.http.Set-Cookie;
85
-
86
- # Deliver the object
87
- return(deliver);
88
- }
89
-
90
- # Called before the response is sent back to the client
91
- sub vcl_deliver {
92
- # Force browsers and intermediary caches to always check back with us
93
- set resp.http.Cache-Control = "private, max-age=0, must-revalidate";
94
- set resp.http.Pragma = "no-cache";
95
-
96
- # Add a header to indicate a cache HIT/MISS
97
- if (obj.hits > 0) {
98
- set resp.http.X-Cache = "HIT";
99
- } else {
100
- set resp.http.X-Cache = "MISS";
101
- }
102
- }
1
+ backend default {
2
+ .host = "<%= backend.split(':').first %>";
3
+ .port = "<%= backend.split(':').last %>";
4
+ }
5
+
6
+ # Handling of requests that are received from clients.
7
+ # First decide whether or not to lookup data in the cache.
8
+ sub vcl_recv {
9
+ # Pipe requests that are non-RFC2616 or CONNECT which is weird.
10
+ if (req.request != "GET" &&
11
+ req.request != "HEAD" &&
12
+ req.request != "PUT" &&
13
+ req.request != "POST" &&
14
+ req.request != "TRACE" &&
15
+ req.request != "OPTIONS" &&
16
+ req.request != "DELETE") {
17
+ return(pipe);
18
+ }
19
+
20
+ if (req.backend.healthy) {
21
+ set req.grace = 30s;
22
+ } else {
23
+ set req.grace = 1h;
24
+ }
25
+
26
+ # Pass requests that are not GET or HEAD
27
+ if (req.request != "GET" && req.request != "HEAD") {
28
+ return(pass);
29
+ }
30
+
31
+ # Handle compression correctly. Varnish treats headers literally, not
32
+ # semantically. So it is very well possible that there are cache misses
33
+ # because the headers sent by different browsers aren't the same.
34
+ # @see: http://varnish.projects.linpro.no/wiki/FAQ/Compression
35
+ if (req.http.Accept-Encoding) {
36
+ if (req.http.Accept-Encoding ~ "gzip") {
37
+ # if the browser supports it, we'll use gzip
38
+ set req.http.Accept-Encoding = "gzip";
39
+ } elsif (req.http.Accept-Encoding ~ "deflate") {
40
+ # next, try deflate if it is supported
41
+ set req.http.Accept-Encoding = "deflate";
42
+ } else {
43
+ # unknown algorithm. Probably junk, remove it
44
+ remove req.http.Accept-Encoding;
45
+ }
46
+ }
47
+
48
+ # Clear cookie and authorization headers, set grace time, lookup in the cache
49
+ unset req.http.Cookie;
50
+ unset req.http.Authorization;
51
+ return(lookup);
52
+ }
53
+
54
+ # Called when entering pipe mode
55
+ sub vcl_pipe {
56
+ # If we don't set the Connection: close header, any following
57
+ # requests from the client will also be piped through and
58
+ # left untouched by varnish. We don't want that.
59
+ set req.http.connection = "close";
60
+ return(pipe);
61
+ }
62
+
63
+ # Called when the requested object has been retrieved from the
64
+ # backend, or the request to the backend has failed
65
+ sub vcl_fetch {
66
+ # Set the grace time
67
+ set beresp.grace = 1h;
68
+
69
+ # Do not cache the object if the status is not in the 200s
70
+ if (beresp.status >= 300) {
71
+ # Remove the Set-Cookie header
72
+ remove beresp.http.Set-Cookie;
73
+ return(<%= Lacquer.configuration.pass_command %>);
74
+ }
75
+
76
+ # Do not cache the object if the backend application does not want us to.
77
+ if (beresp.http.Cache-Control ~ "(no-cache|no-store|private|must-revalidate)") {
78
+ return(<%= Lacquer.configuration.pass_command %>);
79
+ }
80
+
81
+ # Everything below here should be cached
82
+
83
+ # Remove the Set-Cookie header
84
+ remove beresp.http.Set-Cookie;
85
+
86
+ # Deliver the object
87
+ return(deliver);
88
+ }
89
+
90
+ # Called before the response is sent back to the client
91
+ sub vcl_deliver {
92
+ # Force browsers and intermediary caches to always check back with us
93
+ set resp.http.Cache-Control = "private, max-age=0, must-revalidate";
94
+ set resp.http.Pragma = "no-cache";
95
+
96
+ # Add a header to indicate a cache HIT/MISS
97
+ if (obj.hits > 0) {
98
+ set resp.http.X-Cache = "HIT";
99
+ } else {
100
+ set resp.http.X-Cache = "MISS";
101
+ }
102
+ }
@@ -1,26 +1,26 @@
1
- development:
2
- listen: 127.0.0.1:3001
3
- telnet: 127.0.0.1:6082
4
- backend: 127.0.0.1:3000
5
- sbin_path: /usr/local/sbin
6
- storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
7
-
8
- test:
9
- listen: 127.0.0.1:3002
10
- telnet: 127.0.0.1:6083
11
- backend: 127.0.0.1:3000
12
- sbin_path: /usr/local/sbin
13
- storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
14
-
15
- production:
16
- listen: :80
17
- telnet: localhost:6082
18
- backend: backend_server:8080
19
- sbin_path: /usr/local/sbin
20
- storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
21
- params:
22
- overflow_max: 2000
23
- thread_pool_add_delay: 2
24
- thread_pools: 4 # <Number of cpu cores>
25
- thread_pool_min: 200 # <800/number of cpu cores>
26
- thread_pool_max: 4000
1
+ development:
2
+ listen: 127.0.0.1:3001
3
+ telnet: 127.0.0.1:6082
4
+ backend: 127.0.0.1:3000
5
+ sbin_path: /usr/local/sbin
6
+ storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
7
+
8
+ test:
9
+ listen: 127.0.0.1:3002
10
+ telnet: 127.0.0.1:6083
11
+ backend: 127.0.0.1:3000
12
+ sbin_path: /usr/local/sbin
13
+ storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
14
+
15
+ production:
16
+ listen: :80
17
+ telnet: localhost:6082
18
+ backend: backend_server:8080
19
+ sbin_path: /usr/local/sbin
20
+ storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
21
+ params:
22
+ overflow_max: 2000 # for Varnish 2.x ... use "queue_max: 2000" for Varnish 3.x
23
+ thread_pool_add_delay: 2
24
+ thread_pools: 4 # <Number of cpu cores>
25
+ thread_pool_min: 200 # <800/number of cpu cores>
26
+ thread_pool_max: 4000
@@ -11,6 +11,7 @@ Capistrano::Configuration.instance(:must_exit).load do
11
11
 
12
12
  namespace :lacquer do
13
13
  %w( start stop restart global_purge status ).each do |name|
14
+ desc "#{name} varnish"
14
15
  task name.to_sym, :roles => lacquer_roles do
15
16
  next if find_servers_for_task(current_task).empty?
16
17
  run "cd #{current_path} && #{rake} lacquer:varnishd:#{name}"
@@ -1,43 +1,47 @@
1
- module Lacquer
2
- class Configuration
3
- OPTIONS = []
4
-
5
- # Enable cache
6
- attr_accessor :enable_cache
7
-
8
- # Varnish servers
9
- attr_accessor :varnish_servers
10
-
11
- # Application default ttl
12
- attr_accessor :default_ttl
13
-
14
- # Number of retries before failing
15
- attr_accessor :retries
16
-
17
- # Job backend
18
- attr_accessor :job_backend
19
-
20
- # Error handler
21
- attr_accessor :command_error_handler
22
-
23
- # Purge Command
24
- attr_accessor :purge_command
25
-
26
- def initialize
27
- @enable_cache = true
28
- @varnish_servers = []
29
- @default_ttl = 0
30
- @job_backend = :none
31
- @retries = 5
32
- @command_error_handler = nil
33
- @purge_command = "url.purge"
34
- end
35
-
36
- # Returns a hash of all configurable options
37
- def to_hash
38
- OPTIONS.inject({}) do |hash, option|
39
- hash.merge(option.to_sym => send(option))
40
- end
41
- end
42
- end
43
- end
1
+ module Lacquer
2
+ class Configuration
3
+ OPTIONS = []
4
+
5
+ # Enable cache
6
+ attr_accessor :enable_cache
7
+
8
+ # Varnish servers
9
+ attr_accessor :varnish_servers
10
+
11
+ # Application default ttl
12
+ attr_accessor :default_ttl
13
+
14
+ # Number of retries before failing
15
+ attr_accessor :retries
16
+
17
+ # Job backend
18
+ attr_accessor :job_backend
19
+
20
+ # Error handler
21
+ attr_accessor :command_error_handler
22
+
23
+ # Purge Command
24
+ attr_accessor :purge_command
25
+
26
+ # Pass Command (in vcl_fetch)
27
+ attr_accessor :pass_command
28
+
29
+ def initialize
30
+ @enable_cache = true
31
+ @varnish_servers = []
32
+ @default_ttl = 0
33
+ @job_backend = :none
34
+ @retries = 5
35
+ @command_error_handler = nil
36
+ @purge_command = "url.purge"
37
+ @pass_command = "pass"
38
+ end
39
+
40
+ # Returns a hash of all configurable options
41
+ def to_hash
42
+ OPTIONS.inject({}) do |hash, option|
43
+ hash.merge(option.to_sym => send(option))
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module Lacquer
2
- VERSION = '0.5.4'
2
+ VERSION = '0.5.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lacquer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,11 +12,11 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2011-12-05 00:00:00.000000000 Z
15
+ date: 2012-01-11 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
19
- requirement: &70160322129900 !ruby/object:Gem::Requirement
19
+ requirement: &70107447903980 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 2.3.10
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70160322129900
27
+ version_requirements: *70107447903980
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: i18n
30
- requirement: &70160322128420 !ruby/object:Gem::Requirement
30
+ requirement: &70107447914580 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ~>
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '0.4'
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *70160322128420
38
+ version_requirements: *70107447914580
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: erubis
41
- requirement: &70160322127780 !ruby/object:Gem::Requirement
41
+ requirement: &70107447924320 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: '0'
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *70160322127780
49
+ version_requirements: *70107447924320
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rake
52
- requirement: &70160322125760 !ruby/object:Gem::Requirement
52
+ requirement: &70107447921200 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ! '>='
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: '0'
58
58
  type: :development
59
59
  prerelease: false
60
- version_requirements: *70160322125760
60
+ version_requirements: *70107447921200
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec
63
- requirement: &70160322124620 !ruby/object:Gem::Requirement
63
+ requirement: &70107447934240 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ~>
@@ -68,10 +68,10 @@ dependencies:
68
68
  version: '2.5'
69
69
  type: :development
70
70
  prerelease: false
71
- version_requirements: *70160322124620
71
+ version_requirements: *70107447934240
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: yard
74
- requirement: &70160322123360 !ruby/object:Gem::Requirement
74
+ requirement: &70107447929060 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ! '>='
@@ -79,7 +79,7 @@ dependencies:
79
79
  version: '0'
80
80
  type: :development
81
81
  prerelease: false
82
- version_requirements: *70160322123360
82
+ version_requirements: *70107447929060
83
83
  description: Rails drop in for Varnish support.
84
84
  email: russ@bashme.org
85
85
  executables: []
@@ -138,18 +138,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
138
  - - ! '>='
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
- segments:
142
- - 0
143
- hash: -1420781862807341168
144
141
  required_rubygems_version: !ruby/object:Gem::Requirement
145
142
  none: false
146
143
  requirements:
147
144
  - - ! '>='
148
145
  - !ruby/object:Gem::Version
149
146
  version: '0'
150
- segments:
151
- - 0
152
- hash: -1420781862807341168
153
147
  requirements: []
154
148
  rubyforge_project: lacquer
155
149
  rubygems_version: 1.8.10