lacquer 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c26af9cbec46371eaafc94d90f9e37146fd755b
4
- data.tar.gz: 3e2d2c56f33bd746432353929f57a3deeaa78ddb
3
+ metadata.gz: 7e4a8b4a9a84755a126601be54bc9803860568e9
4
+ data.tar.gz: 36865a129cbc936b8839e10b4f3bd72d9b932b54
5
5
  SHA512:
6
- metadata.gz: 6667536d65ae191d360918bab20e9e51794103e2ab9f664e3fc75b725568cde62c7e18bd7e5d53e15930e794ae87885a9454b6e299b442b23a93b576b77d315f
7
- data.tar.gz: bd82245651e7156bc19abc87d34cdff08f708d956b243c84cf38d5e85d005cadc3be13ee5639c6454dffe32133406825dd8ae5aa708b359a25c508951d106acf
6
+ metadata.gz: 489abc465c0eac2d79fefeeb76631c6eb484e2e45115165b92fb897ec55ddd2986f2b9386fdb961a5a9b630f5dda4c7c7f324a8306a2c2c5e027e5321b0507cb
7
+ data.tar.gz: 12dc9282b557e7eba13f439c7805b7a27a340ca529da404d9bd92e60e70cef7297bf00f66a56b7f1af09653e7e66e35ca60b888e27a238b4b506350d591f3d7d
data/README.md ADDED
@@ -0,0 +1,260 @@
1
+ ![http://travis-ci.org/russ/lacquer](https://secure.travis-ci.org/russ/lacquer.png?branch=master)
2
+
3
+ # Lacquer
4
+
5
+ Rails drop in for [Varnish](https://www.varnish-cache.org/) support.
6
+
7
+ ## Install
8
+ This gem requires ruby 1.9+
9
+
10
+ ```text
11
+ gem install lacquer
12
+ rails generate lacquer:install
13
+ ```
14
+
15
+ **config/initializers/lacquer.rb**
16
+
17
+ ```ruby
18
+ Lacquer.configure do |config|
19
+ # Globally enable/disable cache
20
+ config.enable_cache = true
21
+
22
+ # Unless overridden in a controller or action, the default will be used
23
+ config.default_ttl = 1.week
24
+
25
+ # Can be :none, :delayed_job, :resque, :sidekiq
26
+ config.job_backend = :none
27
+
28
+ # Array of Varnish servers to manage
29
+ config.varnish_servers << {
30
+ :host => "0.0.0.0", :port => 6082 # if you have authentication enabled, add :secret => "your secret"
31
+ }
32
+
33
+ # Number of retries
34
+ config.retries = 5
35
+
36
+ # config handler (optional, if you use Hoptoad or another error tracking service)
37
+ config.command_error_handler = lambda { |s| HoptoadNotifier.notify(s) }
38
+
39
+
40
+ ### Varnish - 2.x / 3.x .. VCL-Changes
41
+ ### https://www.varnish-cache.org/docs/trunk/installation/upgrade.html
42
+
43
+ # => Purge Command ( "url.purge" for Varnish 2.x .. "ban.url" for Varnish 3.x )
44
+ # => purges are now called bans in Varnish 3.x .. purge() and purge_url() are now respectively ban() and ban_url()
45
+ config.purge_command = "ban.url"
46
+
47
+ # => VCL_Fetch Pass Command ( "pass" for Varnish 2.x .. "hit_for_pass" for Varnish 3.x )
48
+ # => pass in vcl_fetch renamed to hit_for_pass in Varnish 3.x
49
+ config.pass_command = "pass"
50
+ end
51
+ ```
52
+
53
+ **app/controllers/application_controller.rb**
54
+
55
+ ```ruby
56
+ class ApplicationController < ActionController::Base
57
+ include Lacquer::CacheUtils
58
+ end
59
+ ```
60
+
61
+ **config/varnishd.yml**
62
+ ```yaml
63
+ development:
64
+ listen: localhost:3001
65
+ telnet: localhost:6082
66
+ sbin_path: /usr/local/sbin # path to varnishd
67
+ bin_path: /usr/local/bin # path to varnishadm
68
+ storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
69
+
70
+ test:
71
+ listen: localhost:3002
72
+ telnet: localhost:6083
73
+ sbin_path: /usr/local/sbin
74
+ bin_path: /usr/local/bin
75
+ storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
76
+
77
+ production:
78
+ listen: :80
79
+ telnet: localhost:6082
80
+ sbin_path: /usr/local/sbin
81
+ bin_path: /usr/local/bin
82
+ storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
83
+ params:
84
+ overflow_max: 2000 # for Varnish 2.x ... use "queue_max: 2000" for Varnish 3.x
85
+ thread_pool_add_delay: 2
86
+ thread_pools: 4 # <Number of cpu cores>
87
+ thread_pool_min: 200 # <800/number of cpu cores>
88
+ thread_pool_max: 4000
89
+ ```
90
+
91
+ If only some urls of the application should be cached by varnish, Lacquer::CacheControl will be helpful.
92
+
93
+ **config/initializers/caches.rb**
94
+ ```ruby
95
+ require "lacquer/cache_control"
96
+
97
+ Lacquer.cache_control.configure do |config|
98
+ config.register :static, :url => "^/images",
99
+ :expires_in => "365d"
100
+
101
+ config.register :static, :url => "^/stylesheets",
102
+ :expires_in => "365d"
103
+
104
+ config.register :static, :url => "^/javascripts",
105
+ :expires_in => "365d"
106
+
107
+ config.register :class_section, :url => "^(/[a-z]{2})?/(info_screens|class_sections)/%s.*$",
108
+ :args => "[0-9]+",
109
+ :expires_in => "1m"
110
+
111
+ config.register :open_scoring, :url => "^(/[a-z]{2})?/class_sections/%s/open_scoring.*$",
112
+ :args => "[0-9]+",
113
+ :expires_in => "1m"
114
+
115
+ end
116
+ ```
117
+
118
+ In the sweeper we can do something like this
119
+
120
+ ```ruby
121
+ class_section = ClassSection.find(1)
122
+ Lacquer.cache_control.purge(:open_scoring, class_section)
123
+ ```
124
+
125
+ 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)`
126
+
127
+ The varnish.vcl is preprocssed when starting varnishd with the rake tasks
128
+
129
+ `rake lacquer:varnishd:start`
130
+
131
+ **config/varnish.vcl.erb**
132
+
133
+ ```vcl
134
+ sub vcl_recv {
135
+ # Lookup requests that we know should be cached
136
+ if (<%= Lacquer.cache_control.to_vcl_conditions %>) {
137
+ # Clear cookie and authorization headers, set grace time, lookup in the cache
138
+ unset req.http.Cookie;
139
+ unset req.http.Authorization;
140
+ return(lookup);
141
+ }
142
+
143
+ # Generates
144
+ #
145
+ # if(req.url ~ "^/images" ||
146
+ # req.url ~ "^/stylesheets" ||
147
+ # req.url ~ "^/javascripts" ||
148
+ # req.url ~ "^(/[a-z]{2})?/(info_screens|class_sections)/[0-9]+.*$" ||
149
+ # req.url ~ "^(/[a-z]{2})?/class_sections/[0-9]+/open_scoring.*$") {
150
+ # unset req.http.Cookie;
151
+ # unset req.http.Authorization;
152
+ # return(lookup);
153
+ # }
154
+ }
155
+
156
+ sub vcl_fetch {
157
+ <%= Lacquer.cache_control.to_vcl_override_ttl_urls %>
158
+
159
+ # Generates
160
+ #
161
+ # if(req.url ~ "^/images" || req.url ~ "^/stylesheets" || req.url ~ "^/javascripts") {
162
+ # unset beresp.http.Set-Cookie;
163
+ # set beresp.ttl = 365d;
164
+ # return(deliver);
165
+ # }
166
+ #
167
+ # if(req.url ~ "^(/[a-z]{2})?/(info_screens|class_sections)/[0-9]+.*$" ||
168
+ # req.url ~ "^(/[a-z]{2})?/class_sections/[0-9]+/open_scoring.*$") {
169
+ # unset beresp.http.Set-Cookie;
170
+ # set beresp.ttl = 1m;
171
+ # return(deliver);
172
+ # }
173
+ }
174
+ ```
175
+
176
+ This makes it much simpler to perform cacheing, it's only setuped in one place, purge it or just let it expire.
177
+
178
+ ## Usage
179
+
180
+ To set a custom ttl for a controller:
181
+
182
+ `before_filter { |controller| controller.set_cache_ttl(15.minutes) }`
183
+
184
+ Clearing the cache:
185
+
186
+ ```ruby
187
+ class Posts < ApplicationController
188
+ after_filter :clear_cache, :only => [ :create, :update, :destroy ]
189
+
190
+ private
191
+
192
+ def clear_cache
193
+ clear_cache_for(
194
+ root_path,
195
+ posts_path,
196
+ post_path(@post))
197
+ end
198
+ end
199
+ ```
200
+
201
+ Control varnishd with the following rake tasks
202
+
203
+ ```text
204
+ rake lacquer:varnishd:start
205
+ rake lacquer:varnishd:stop
206
+ rake lacquer:varnishd:restart
207
+ rake lacquer:varnishd:reload
208
+ rake lacquer:varnishd:status
209
+ rake lacquer:varnishd:global_purge
210
+ ```
211
+
212
+ ## Deployment
213
+ Lacquer supports Capistrano 2.5+
214
+
215
+ For Capistrano 2.5 just add `require 'lacquer/capistrano'` to your `config/deploy.rb` file.
216
+
217
+ For Capistrano 3+ add `require 'lacquer/capistrano'` to your `Capfile`.
218
+
219
+ ```ruby
220
+ # Capfile
221
+ require 'capistrano/setup'
222
+ require 'capistrano/deploy'
223
+ require 'capistrano/rails/assets'
224
+ require 'capistrano/rails/migrations'
225
+ require 'lacquer/capistrano'
226
+ ```
227
+
228
+ Adding this will give you the following cap tasks
229
+
230
+ ```text
231
+ cap lacquer:global_purge # global_purge varnish
232
+ cap lacquer:restart # restart varnish
233
+ cap lacquer:start # start varnish
234
+ cap lacquer:status # status varnish
235
+ cap lacquer:stop # stop varnish
236
+ ```
237
+
238
+ ## Gotchas
239
+
240
+ 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:
241
+
242
+ Cache-Control: max-age=0, no-cache, private
243
+
244
+ 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.
245
+
246
+ 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.
247
+
248
+ As a result, all you have to do to set a cacheable action is the before filter above.
249
+
250
+ ## Note on Patches/Pull Requests
251
+
252
+ * Fork the project.
253
+ * Make your feature addition or bug fix.
254
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
255
+ * 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)
256
+ * Send me a pull request. Bonus points for topic branches.
257
+
258
+ ## Copyright
259
+
260
+ Copyright (c) 2015 Russ Smith. See LICENSE for details.
@@ -9,7 +9,7 @@ namespace :lacquer do
9
9
  desc "#{name} varnish"
10
10
  task name.to_sym do
11
11
  on roles(fetch(:lacquer_roles)) do
12
- within current_path do
12
+ within current_release do
13
13
  with rails_env: fetch(:rails_env) do
14
14
  execute :bundle, "exec rake", "lacquer:varnishd:#{name}"
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module Lacquer
2
- VERSION = '0.6.1'
2
+ VERSION = '0.6.2'
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.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russ Smith (russ@bashme.org)
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-02-20 00:00:00.000000000 Z
14
+ date: 2015-04-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -108,7 +108,7 @@ files:
108
108
  - ".travis.yml"
109
109
  - Gemfile
110
110
  - LICENSE
111
- - README.rdoc
111
+ - README.md
112
112
  - Rakefile
113
113
  - init.rb
114
114
  - lacquer.gemspec
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  version: '0'
167
167
  requirements: []
168
168
  rubyforge_project: lacquer
169
- rubygems_version: 2.2.0
169
+ rubygems_version: 2.4.5
170
170
  signing_key:
171
171
  specification_version: 4
172
172
  summary: Rails drop in for Varnish support.
@@ -182,4 +182,3 @@ test_files:
182
182
  - spec/lacquer/varnish_spec.rb
183
183
  - spec/lacquer/varnishd_spec.rb
184
184
  - spec/spec_helper.rb
185
- has_rdoc:
data/README.rdoc DELETED
@@ -1,220 +0,0 @@
1
- {<img src="https://secure.travis-ci.org/russ/lacquer.png?branch=master" alt="Build Status" />}[http://travis-ci.org/russ/lacquer]
2
-
3
- = lacquer
4
-
5
- Rails drop in for Varnish support.
6
-
7
- == Install
8
- This gem requires ruby 1.9
9
-
10
- Basic installation
11
-
12
- sudo gem install lacquer
13
- rails generate lacquer:install
14
-
15
- config/initializers/lacquer.rb
16
-
17
- Lacquer.configure do |config|
18
- # Globally enable/disable cache
19
- config.enable_cache = true
20
-
21
- # Unless overridden in a controller or action, the default will be used
22
- config.default_ttl = 1.week
23
-
24
- # Can be :none, :delayed_job, :resque
25
- config.job_backend = :none
26
-
27
- # Array of Varnish servers to manage
28
- config.varnish_servers << {
29
- :host => "0.0.0.0", :port => 6082 # if you have authentication enabled, add :secret => "your secret"
30
- }
31
-
32
- # Number of retries
33
- config.retries = 5
34
-
35
- # config handler (optional, if you use Hoptoad or another error tracking service)
36
- config.command_error_handler = lambda { |s| HoptoadNotifier.notify(s) }
37
-
38
-
39
- ### Varnish - 2.x / 3.x .. VCL-Changes
40
- ### https://www.varnish-cache.org/docs/trunk/installation/upgrade.html
41
-
42
- # => Purge Command ( "url.purge" for Varnish 2.x .. "ban.url" for Varnish 3.x )
43
- # => purges are now called bans in Varnish 3.x .. purge() and purge_url() are now respectively ban() and ban_url()
44
- config.purge_command = "ban.url"
45
-
46
- # => VCL_Fetch Pass Command ( "pass" for Varnish 2.x .. "hit_for_pass" for Varnish 3.x )
47
- # => pass in vcl_fetch renamed to hit_for_pass in Varnish 3.x
48
- config.pass_command = "pass"
49
- end
50
-
51
- app/controllers/application_controller.rb
52
-
53
- class ApplicationController < ActionController::Base
54
- include Lacquer::CacheUtils
55
- end
56
-
57
- config/varnishd.yml
58
-
59
- development:
60
- listen: localhost:3001
61
- telnet: localhost:6082
62
- sbin_path: /usr/local/sbin # path to varnishd
63
- bin_path: /usr/local/bin # path to varnishadm
64
- storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
65
-
66
- test:
67
- listen: localhost:3002
68
- telnet: localhost:6083
69
- sbin_path: /usr/local/sbin
70
- bin_path: /usr/local/bin
71
- storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
72
-
73
- production:
74
- listen: :80
75
- telnet: localhost:6082
76
- sbin_path: /usr/local/sbin
77
- bin_path: /usr/local/bin
78
- storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,100MB"
79
- params:
80
- overflow_max: 2000 # for Varnish 2.x ... use "queue_max: 2000" for Varnish 3.x
81
- thread_pool_add_delay: 2
82
- thread_pools: 4 # <Number of cpu cores>
83
- thread_pool_min: 200 # <800/number of cpu cores>
84
- thread_pool_max: 4000
85
-
86
- If only some urls of the application should be cached by varnish, Lacquer::CacheControl will be helpful.
87
-
88
- config/initializers/caches.rb
89
-
90
- require "lacquer/cache_control"
91
-
92
- Lacquer.cache_control.configure do |config|
93
- config.register :static, :url => "^/images",
94
- :expires_in => "365d"
95
-
96
- config.register :static, :url => "^/stylesheets",
97
- :expires_in => "365d"
98
-
99
- config.register :static, :url => "^/javascripts",
100
- :expires_in => "365d"
101
-
102
- config.register :class_section, :url => "^(/[a-z]{2})?/(info_screens|class_sections)/%s.*$",
103
- :args => "[0-9]+",
104
- :expires_in => "1m"
105
-
106
- config.register :open_scoring, :url => "^(/[a-z]{2})?/class_sections/%s/open_scoring.*$",
107
- :args => "[0-9]+",
108
- :expires_in => "1m"
109
-
110
- end
111
-
112
- In the sweeper we can do something like this
113
-
114
- class_section = ClassSection.find(1)
115
- Lacquer.cache_control.purge(:open_scoring, class_section)
116
-
117
- 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)
118
-
119
- The varnish.vcl is preprocssed when starting varnishd with the rake tasks
120
-
121
- rake lacquer:varnishd:start
122
-
123
- config/varnish.vcl.erb
124
-
125
- sub vcl_recv {
126
- # Lookup requests that we know should be cached
127
- if (<%= Lacquer.cache_control.to_vcl_conditions %>) {
128
- # Clear cookie and authorization headers, set grace time, lookup in the cache
129
- unset req.http.Cookie;
130
- unset req.http.Authorization;
131
- return(lookup);
132
- }
133
-
134
- # Generates
135
- #
136
- # if(req.url ~ "^/images" ||
137
- # req.url ~ "^/stylesheets" ||
138
- # req.url ~ "^/javascripts" ||
139
- # req.url ~ "^(/[a-z]{2})?/(info_screens|class_sections)/[0-9]+.*$" ||
140
- # req.url ~ "^(/[a-z]{2})?/class_sections/[0-9]+/open_scoring.*$") {
141
- # unset req.http.Cookie;
142
- # unset req.http.Authorization;
143
- # return(lookup);
144
- # }
145
- }
146
-
147
- sub vcl_fetch {
148
- <%= Lacquer.cache_control.to_vcl_override_ttl_urls %>
149
-
150
- # Generates
151
- #
152
- # if(req.url ~ "^/images" || req.url ~ "^/stylesheets" || req.url ~ "^/javascripts") {
153
- # unset beresp.http.Set-Cookie;
154
- # set beresp.ttl = 365d;
155
- # return(deliver);
156
- # }
157
- #
158
- # if(req.url ~ "^(/[a-z]{2})?/(info_screens|class_sections)/[0-9]+.*$" ||
159
- # req.url ~ "^(/[a-z]{2})?/class_sections/[0-9]+/open_scoring.*$") {
160
- # unset beresp.http.Set-Cookie;
161
- # set beresp.ttl = 1m;
162
- # return(deliver);
163
- # }
164
- }
165
-
166
- This makes it much simpler to perform cacheing, it's only setuped in one place, purge it or just let it expire.
167
-
168
- == Usage
169
-
170
- To set a custom ttl for a controller:
171
-
172
- before_filter { |controller| controller.set_cache_ttl(15.minutes) }
173
-
174
- Clearing the cache:
175
-
176
- class Posts < ApplicationController
177
- after_filter :clear_cache, :only => [ :create, :update, :destroy ]
178
-
179
- private
180
-
181
- def clear_cache
182
- clear_cache_for(
183
- root_path,
184
- posts_path,
185
- post_path(@post))
186
- end
187
- end
188
-
189
- Control varnishd with the following rake tasks
190
-
191
- rake lacquer:varnishd:start
192
- rake lacquer:varnishd:stop
193
- rake lacquer:varnishd:restart
194
- rake lacquer:varnishd:reload
195
- rake lacquer:varnishd:status
196
- rake lacquer:varnishd:global_purge
197
-
198
- == Gotchas
199
-
200
- 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:
201
-
202
- Cache-Control: max-age=0, no-cache, private
203
-
204
- 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.
205
-
206
- 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.
207
-
208
- As a result, all you have to do to set a cacheable action is the before filter above.
209
-
210
- == Note on Patches/Pull Requests
211
-
212
- * Fork the project.
213
- * Make your feature addition or bug fix.
214
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
215
- * 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)
216
- * Send me a pull request. Bonus points for topic branches.
217
-
218
- == Copyright
219
-
220
- Copyright (c) 2010 Russ Smith. See LICENSE for details.