lacquer 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -0
- data/.gitignore +2 -2
- data/Gemfile +8 -0
- data/Gemfile.lock +39 -0
- data/README.rdoc +13 -15
- data/Rakefile +17 -25
- data/VERSION +1 -1
- data/lacquer.gemspec +18 -12
- data/lib/generators/lacquer/USAGE +8 -0
- data/lib/generators/lacquer/install_generator.rb +15 -0
- data/lib/generators/{templates → lacquer/templates}/initializer.rb +8 -2
- data/lib/generators/{templates → lacquer/templates}/varnish.sample.vcl +0 -15
- data/lib/lacquer.rb +10 -10
- data/lib/lacquer/cache_utils.rb +8 -6
- data/lib/lacquer/configuration.rb +3 -3
- data/lib/lacquer/delayed_job_job.rb +2 -2
- data/lib/lacquer/resque_job.rb +3 -3
- data/lib/lacquer/varnish.rb +2 -1
- data/spec/lacquer/cache_utils_spec.rb +18 -1
- data/spec/lacquer/delayed_job_job_spec.rb +13 -0
- data/spec/lacquer/resque_job_spec.rb +13 -0
- data/spec/spec_helper.rb +10 -6
- metadata +23 -15
- data/lib/generators/USAGE +0 -5
- data/lib/generators/lacquer_generator.rb +0 -10
- data/spec/spec.opts +0 -1
data/.bundle/config
ADDED
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.1)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
gemcutter (0.5.0)
|
7
|
+
json_pure
|
8
|
+
git (1.2.5)
|
9
|
+
i18n (0.4.1)
|
10
|
+
jeweler (1.4.0)
|
11
|
+
gemcutter (>= 0.1.0)
|
12
|
+
git (>= 1.2.5)
|
13
|
+
rubyforge (>= 2.0.0)
|
14
|
+
json_pure (1.4.6)
|
15
|
+
rake (0.8.7)
|
16
|
+
rspec (2.0.0)
|
17
|
+
rspec-core (= 2.0.0)
|
18
|
+
rspec-expectations (= 2.0.0)
|
19
|
+
rspec-mocks (= 2.0.0)
|
20
|
+
rspec-core (2.0.0)
|
21
|
+
rspec-expectations (2.0.0)
|
22
|
+
diff-lcs (>= 1.1.2)
|
23
|
+
rspec-mocks (2.0.0)
|
24
|
+
rspec-core (= 2.0.0)
|
25
|
+
rspec-expectations (= 2.0.0)
|
26
|
+
rubyforge (2.0.4)
|
27
|
+
json_pure (>= 1.1.7)
|
28
|
+
yard (0.6.1)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
activesupport (= 3.0.1)
|
35
|
+
i18n (= 0.4.1)
|
36
|
+
jeweler
|
37
|
+
rake
|
38
|
+
rspec (= 2.0.0)
|
39
|
+
yard
|
data/README.rdoc
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
= lacquer
|
2
2
|
|
3
|
-
Rails drop in for Varnish support.
|
3
|
+
Rails drop in for Varnish support.
|
4
4
|
|
5
5
|
== Install
|
6
6
|
Basic installation
|
7
7
|
|
8
|
-
sudo gem install
|
8
|
+
sudo gem install lacquer
|
9
9
|
|
10
10
|
config/initializers/lacquer.rb
|
11
11
|
|
@@ -20,15 +20,15 @@ config/initializers/lacquer.rb
|
|
20
20
|
config.job_backend = :none
|
21
21
|
|
22
22
|
# Array of Varnish servers to manage
|
23
|
-
config.varnish_servers << {
|
24
|
-
:host =>
|
23
|
+
config.varnish_servers << {
|
24
|
+
:host => "0.0.0.0", :port => 6082
|
25
25
|
}
|
26
26
|
|
27
27
|
# Number of retries
|
28
28
|
config.retries = 5
|
29
29
|
|
30
30
|
# config handler (optional, if you use Hoptoad or another error tracking service)
|
31
|
-
config.command_error_handler = lambda {|s| HoptoadNotifier.notify(s) }
|
31
|
+
config.command_error_handler = lambda { |s| HoptoadNotifier.notify(s) }
|
32
32
|
end
|
33
33
|
|
34
34
|
app/controllers/application_controller.rb
|
@@ -60,25 +60,23 @@ Clearing the cache:
|
|
60
60
|
|
61
61
|
== Gotchas
|
62
62
|
|
63
|
-
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
|
63
|
+
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:
|
64
64
|
|
65
65
|
Cache-Control: max-age=0, no-cache, private
|
66
66
|
|
67
|
-
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.
|
67
|
+
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.
|
68
68
|
|
69
69
|
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.
|
70
70
|
|
71
|
-
As a result, all you have to do to set a cacheable action is the before filter above.
|
71
|
+
As a result, all you have to do to set a cacheable action is the before filter above.
|
72
72
|
|
73
73
|
== Note on Patches/Pull Requests
|
74
74
|
|
75
|
-
* Fork the project.
|
76
|
-
* Make your feature addition or bug fix.
|
77
|
-
* Add tests for it. This is important so I don't break it in a
|
78
|
-
|
79
|
-
*
|
80
|
-
(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)
|
81
|
-
* Send me a pull request. Bonus points for topic branches.
|
75
|
+
* Fork the project.
|
76
|
+
* Make your feature addition or bug fix.
|
77
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
78
|
+
* 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)
|
79
|
+
* Send me a pull request. Bonus points for topic branches.
|
82
80
|
|
83
81
|
== Copyright
|
84
82
|
|
data/Rakefile
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
|
4
|
+
require "rake"
|
5
|
+
require "yard"
|
6
|
+
require "rspec"
|
7
|
+
require "rspec/core/rake_task"
|
3
8
|
|
4
9
|
begin
|
5
10
|
require 'jeweler'
|
@@ -9,8 +14,8 @@ begin
|
|
9
14
|
gem.description = %Q{Rails drop in for Varnish support.}
|
10
15
|
gem.email = "russ@bashme.org"
|
11
16
|
gem.homepage = "http://github.com/russ/lacquer"
|
12
|
-
gem.authors = ["Russ Smith"]
|
13
|
-
gem.add_development_dependency "rspec", "
|
17
|
+
gem.authors = ["Russ Smith (russ@bashme.org)", "Ryan Johns", "Garry Tan (garry@posterous.com), Gabe da Silveira (gabe@websaviour.com)"]
|
18
|
+
gem.add_development_dependency "rspec", "~> 1.3.0"
|
14
19
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
20
|
end
|
16
21
|
Jeweler::GemcutterTasks.new
|
@@ -18,28 +23,15 @@ rescue LoadError
|
|
18
23
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
24
|
end
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
desc "Run all examples"
|
27
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
28
|
+
t.rspec_path = "rspec"
|
29
|
+
t.rspec_opts = %w[--color]
|
25
30
|
end
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
spec.rcov = true
|
32
|
+
YARD::Rake::YardocTask.new do |t|
|
33
|
+
t.files = [ "lib/**/*.rb" ]
|
34
|
+
t.options = [ "--no-private" ]
|
31
35
|
end
|
32
36
|
|
33
|
-
task :
|
34
|
-
|
35
|
-
task :default => :spec
|
36
|
-
|
37
|
-
require 'rake/rdoctask'
|
38
|
-
Rake::RDocTask.new do |rdoc|
|
39
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
-
|
41
|
-
rdoc.rdoc_dir = 'rdoc'
|
42
|
-
rdoc.title = "testing #{version}"
|
43
|
-
rdoc.rdoc_files.include('README*')
|
44
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
-
end
|
37
|
+
task :default => [ :spec ]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lacquer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{lacquer}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Russ Smith"]
|
12
|
-
s.date = %q{2010-
|
11
|
+
s.authors = ["Russ Smith (russ@bashme.org)", "Ryan Johns", "Garry Tan (garry@posterous.com), Gabe da Silveira (gabe@websaviour.com)"]
|
12
|
+
s.date = %q{2010-11-03}
|
13
13
|
s.description = %q{Rails drop in for Varnish support.}
|
14
14
|
s.email = %q{russ@bashme.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -17,18 +17,21 @@ Gem::Specification.new do |s|
|
|
17
17
|
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
".
|
20
|
+
".bundle/config",
|
21
|
+
".document",
|
21
22
|
".gitignore",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
22
25
|
"LICENSE",
|
23
26
|
"README.rdoc",
|
24
27
|
"Rakefile",
|
25
28
|
"VERSION",
|
26
29
|
"init.rb",
|
27
30
|
"lacquer.gemspec",
|
28
|
-
"lib/generators/USAGE",
|
29
|
-
"lib/generators/
|
30
|
-
"lib/generators/templates/initializer.rb",
|
31
|
-
"lib/generators/templates/varnish.sample.vcl",
|
31
|
+
"lib/generators/lacquer/USAGE",
|
32
|
+
"lib/generators/lacquer/install_generator.rb",
|
33
|
+
"lib/generators/lacquer/templates/initializer.rb",
|
34
|
+
"lib/generators/lacquer/templates/varnish.sample.vcl",
|
32
35
|
"lib/lacquer.rb",
|
33
36
|
"lib/lacquer/cache_utils.rb",
|
34
37
|
"lib/lacquer/configuration.rb",
|
@@ -37,8 +40,9 @@ Gem::Specification.new do |s|
|
|
37
40
|
"lib/lacquer/varnish.rb",
|
38
41
|
"rails/init.rb",
|
39
42
|
"spec/lacquer/cache_utils_spec.rb",
|
43
|
+
"spec/lacquer/delayed_job_job_spec.rb",
|
44
|
+
"spec/lacquer/resque_job_spec.rb",
|
40
45
|
"spec/lacquer/varnish_spec.rb",
|
41
|
-
"spec/spec.opts",
|
42
46
|
"spec/spec_helper.rb"
|
43
47
|
]
|
44
48
|
s.homepage = %q{http://github.com/russ/lacquer}
|
@@ -48,6 +52,8 @@ Gem::Specification.new do |s|
|
|
48
52
|
s.summary = %q{Rails drop in for Varnish support.}
|
49
53
|
s.test_files = [
|
50
54
|
"spec/lacquer/cache_utils_spec.rb",
|
55
|
+
"spec/lacquer/delayed_job_job_spec.rb",
|
56
|
+
"spec/lacquer/resque_job_spec.rb",
|
51
57
|
"spec/lacquer/varnish_spec.rb",
|
52
58
|
"spec/spec_helper.rb"
|
53
59
|
]
|
@@ -57,12 +63,12 @@ Gem::Specification.new do |s|
|
|
57
63
|
s.specification_version = 3
|
58
64
|
|
59
65
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
|
-
s.add_development_dependency(%q<rspec>, ["
|
66
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
|
61
67
|
else
|
62
|
-
s.add_dependency(%q<rspec>, ["
|
68
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
63
69
|
end
|
64
70
|
else
|
65
|
-
s.add_dependency(%q<rspec>, ["
|
71
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Lacquer
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), "templates"))
|
5
|
+
|
6
|
+
def copy_initializer
|
7
|
+
copy_file("initializer.rb", "config/initializers/lacquer.rb")
|
8
|
+
end
|
9
|
+
|
10
|
+
def copy_vcl
|
11
|
+
copy_file("varnish.sample.vcl", "config/varnish.sample.vcl")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -9,7 +9,13 @@ Lacquer.configure do |config|
|
|
9
9
|
config.job_backend = :none
|
10
10
|
|
11
11
|
# Array of Varnish servers to manage
|
12
|
-
config.varnish_servers << {
|
13
|
-
:host =>
|
12
|
+
config.varnish_servers << {
|
13
|
+
:host => "0.0.0.0", :port => 6082
|
14
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) }
|
15
21
|
end
|
@@ -3,11 +3,8 @@ backend default {
|
|
3
3
|
.port = "10000";
|
4
4
|
}
|
5
5
|
|
6
|
-
|
7
|
-
#
|
8
6
|
# Handling of requests that are received from clients.
|
9
7
|
# First decide whether or not to lookup data in the cache.
|
10
|
-
#
|
11
8
|
sub vcl_recv {
|
12
9
|
# Pipe requests that are non-RFC2616 or CONNECT which is weird.
|
13
10
|
if (req.request != "GET" &&
|
@@ -30,10 +27,6 @@ sub vcl_recv {
|
|
30
27
|
pass;
|
31
28
|
}
|
32
29
|
|
33
|
-
#
|
34
|
-
# Everything below here should be cached
|
35
|
-
#
|
36
|
-
|
37
30
|
# Handle compression correctly. Varnish treats headers literally, not
|
38
31
|
# semantically. So it is very well possible that there are cache misses
|
39
32
|
# because the headers sent by different browsers aren't the same.
|
@@ -58,9 +51,7 @@ sub vcl_recv {
|
|
58
51
|
lookup;
|
59
52
|
}
|
60
53
|
|
61
|
-
#
|
62
54
|
# Called when entering pipe mode
|
63
|
-
#
|
64
55
|
sub vcl_pipe {
|
65
56
|
# If we don't set the Connection: close header, any following
|
66
57
|
# requests from the client will also be piped through and
|
@@ -69,10 +60,8 @@ sub vcl_pipe {
|
|
69
60
|
pipe;
|
70
61
|
}
|
71
62
|
|
72
|
-
#
|
73
63
|
# Called when the requested object has been retrieved from the
|
74
64
|
# backend, or the request to the backend has failed
|
75
|
-
#
|
76
65
|
sub vcl_fetch {
|
77
66
|
# Do not cache the object if the backend application does not want us to.
|
78
67
|
if (obj.http.Cache-Control ~ "(no-cache|no-store|private|must-revalidate)") {
|
@@ -86,9 +75,7 @@ sub vcl_fetch {
|
|
86
75
|
pass;
|
87
76
|
}
|
88
77
|
|
89
|
-
#
|
90
78
|
# Everything below here should be cached
|
91
|
-
#
|
92
79
|
|
93
80
|
# Remove the Set-Cookie header
|
94
81
|
remove obj.http.Set-Cookie;
|
@@ -100,9 +87,7 @@ sub vcl_fetch {
|
|
100
87
|
deliver;
|
101
88
|
}
|
102
89
|
|
103
|
-
#
|
104
90
|
# Called before the response is sent back to the client
|
105
|
-
#
|
106
91
|
sub vcl_deliver {
|
107
92
|
# Force browsers and intermediary caches to always check back with us
|
108
93
|
set resp.http.Cache-Control = "private, max-age=0, must-revalidate";
|
data/lib/lacquer.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "net/telnet"
|
3
|
+
require "active_support/core_ext"
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
5
|
+
require "lacquer/configuration"
|
6
|
+
require "lacquer/cache_utils"
|
7
|
+
require "lacquer/varnish"
|
8
8
|
|
9
9
|
module Lacquer
|
10
|
-
class VarnishError < Exception; end
|
10
|
+
class VarnishError < Exception; end # @private
|
11
11
|
|
12
12
|
class << self
|
13
13
|
attr_accessor :configuration
|
14
14
|
|
15
15
|
# Call this method to modify defaults in your initailizers.
|
16
16
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
17
|
+
# Lacquer.configure do |config|
|
18
|
+
# config.varnish_servers << { :host => '0.0.0.0', :port => 6082, :timeout => 5 }
|
19
|
+
# end
|
20
20
|
def configure
|
21
21
|
self.configuration ||= Configuration.new
|
22
22
|
yield(configuration)
|
data/lib/lacquer/cache_utils.rb
CHANGED
@@ -4,8 +4,10 @@ module Lacquer
|
|
4
4
|
base.class_eval do
|
5
5
|
attr_reader :cache_ttl
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
if respond_to? :before_filter
|
8
|
+
before_filter :set_default_cache_ttl
|
9
|
+
after_filter :send_cache_control_headers
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
@@ -28,12 +30,12 @@ module Lacquer
|
|
28
30
|
case Lacquer.configuration.job_backend
|
29
31
|
when :delayed_job
|
30
32
|
require 'lacquer/delayed_job_job'
|
31
|
-
Delayed::Job.enqueue(Lacquer::DelayedJobJob.new(
|
33
|
+
Delayed::Job.enqueue(Lacquer::DelayedJobJob.new(path))
|
32
34
|
when :resque
|
33
35
|
require 'lacquer/resque_job'
|
34
|
-
Resque.enqueue(Lacquer::ResqueJob,
|
36
|
+
Resque.enqueue(Lacquer::ResqueJob, path)
|
35
37
|
when :none
|
36
|
-
Varnish.new.purge(
|
38
|
+
Varnish.new.purge(path)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
@@ -43,7 +45,7 @@ module Lacquer
|
|
43
45
|
# to set cache properly.
|
44
46
|
def send_cache_control_headers
|
45
47
|
if Lacquer.configuration.enable_cache && @cache_ttl && @cache_ttl != 0
|
46
|
-
expires_in(@cache_ttl, :public => true
|
48
|
+
expires_in(@cache_ttl, :public => true)
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Lacquer
|
2
2
|
class Configuration
|
3
|
-
OPTIONS = [
|
3
|
+
OPTIONS = []
|
4
4
|
|
5
5
|
# Enable cache
|
6
6
|
attr_accessor :enable_cache
|
@@ -11,10 +11,10 @@ module Lacquer
|
|
11
11
|
# Application default ttl
|
12
12
|
attr_accessor :default_ttl
|
13
13
|
|
14
|
-
#
|
14
|
+
# Number of retries before failing
|
15
15
|
attr_accessor :retries
|
16
16
|
|
17
|
-
# Job
|
17
|
+
# Job backend
|
18
18
|
attr_accessor :job_backend
|
19
19
|
|
20
20
|
# Error handler
|
data/lib/lacquer/resque_job.rb
CHANGED
data/lib/lacquer/varnish.rb
CHANGED
@@ -11,6 +11,7 @@ module Lacquer
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
# Sends the command 'url.purge *path*'
|
14
15
|
def purge(path)
|
15
16
|
send_command('url.purge ' << path).all? do |result|
|
16
17
|
result =~ /200/
|
@@ -28,7 +29,7 @@ module Lacquer
|
|
28
29
|
'Host' => server[:host],
|
29
30
|
'Port' => server[:port],
|
30
31
|
'Timeout' => server[:timeout] || 5)
|
31
|
-
connection.cmd(command
|
32
|
+
connection.cmd('String' => command, 'Match' => /\n\n/) {|r| response = r.split("\n").first.strip}
|
32
33
|
connection.close
|
33
34
|
rescue Exception => e
|
34
35
|
if retries < Lacquer.configuration.retries
|
@@ -12,12 +12,19 @@ describe "Lacquer" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "when backend is :none" do
|
15
|
-
|
15
|
+
before(:each) do
|
16
16
|
Lacquer.configuration.job_backend = :none
|
17
|
+
end
|
17
18
|
|
19
|
+
it "sends commands to varnish instantly" do
|
18
20
|
@varnish_stub.should_receive(:purge).twice
|
19
21
|
@controller.clear_cache_for('/', '/blog/posts')
|
20
22
|
end
|
23
|
+
|
24
|
+
it "calls purge with the correct parameter" do
|
25
|
+
@varnish_stub.should_receive(:purge).with('/')
|
26
|
+
@controller.clear_cache_for('/')
|
27
|
+
end
|
21
28
|
end
|
22
29
|
|
23
30
|
describe "when backend is :delayed_job" do
|
@@ -61,4 +68,14 @@ describe "Lacquer" do
|
|
61
68
|
end
|
62
69
|
end
|
63
70
|
end
|
71
|
+
|
72
|
+
it "should allow purge by non-controller sweepers" do
|
73
|
+
@varnish_stub = mock('varnish')
|
74
|
+
Lacquer::Varnish.stub!(:new).and_return(@varnish_stub)
|
75
|
+
|
76
|
+
@sweeper = SweeperClass.new
|
77
|
+
|
78
|
+
@varnish_stub.should_receive(:purge)
|
79
|
+
@sweeper.clear_cache_for('/')
|
80
|
+
end
|
64
81
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
2
|
+
|
3
|
+
describe "DelayedJobJob" do
|
4
|
+
describe "perform" do
|
5
|
+
it "should purge the parameter" do
|
6
|
+
@varnish_mock = mock('varnish')
|
7
|
+
Lacquer::Varnish.stub!(:new).and_return(@varnish_mock)
|
8
|
+
|
9
|
+
@varnish_mock.should_receive(:purge).with('/').exactly(1).times
|
10
|
+
Lacquer::DelayedJobJob.new('/').perform
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
2
|
+
|
3
|
+
describe "ResqueJob" do
|
4
|
+
describe "perform" do
|
5
|
+
it "should purge the parameter" do
|
6
|
+
@varnish_mock = mock('varnish')
|
7
|
+
Lacquer::Varnish.stub!(:new).and_return(@varnish_mock)
|
8
|
+
|
9
|
+
@varnish_mock.should_receive(:purge).with('/').exactly(1).times
|
10
|
+
Lacquer::ResqueJob.perform('/')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require 'spec/autorun'
|
4
|
+
require "lacquer"
|
5
|
+
require "rspec"
|
7
6
|
|
8
7
|
class ControllerClass
|
9
8
|
def self.before_filter(arg); end
|
@@ -12,6 +11,10 @@ class ControllerClass
|
|
12
11
|
include Lacquer::CacheUtils
|
13
12
|
end
|
14
13
|
|
14
|
+
class SweeperClass
|
15
|
+
include Lacquer::CacheUtils
|
16
|
+
end
|
17
|
+
|
15
18
|
module Delayed;
|
16
19
|
module Job; end
|
17
20
|
end
|
@@ -22,8 +25,9 @@ Lacquer.configure do |config|
|
|
22
25
|
config.enable_cache = true
|
23
26
|
config.default_ttl = 1.week
|
24
27
|
config.job_backend = :none
|
25
|
-
config.varnish_servers << { :host =>
|
28
|
+
config.varnish_servers << { :host => "0.0.0.0", :port => 6082 }
|
26
29
|
end
|
27
30
|
|
28
|
-
|
31
|
+
Rspec.configure do |c|
|
32
|
+
c.mock_with :rspec
|
29
33
|
end
|
metadata
CHANGED
@@ -1,30 +1,33 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lacquer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
- Russ Smith
|
13
|
+
- Russ Smith (russ@bashme.org)
|
14
|
+
- Ryan Johns
|
15
|
+
- Garry Tan (garry@posterous.com), Gabe da Silveira (gabe@websaviour.com)
|
14
16
|
autorequire:
|
15
17
|
bindir: bin
|
16
18
|
cert_chain: []
|
17
19
|
|
18
|
-
date: 2010-
|
20
|
+
date: 2010-11-03 00:00:00 -07:00
|
19
21
|
default_executable:
|
20
22
|
dependencies:
|
21
23
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
24
|
+
type: :development
|
23
25
|
prerelease: false
|
24
|
-
|
26
|
+
name: rspec
|
27
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
28
|
none: false
|
26
29
|
requirements:
|
27
|
-
- -
|
30
|
+
- - ~>
|
28
31
|
- !ruby/object:Gem::Version
|
29
32
|
hash: 27
|
30
33
|
segments:
|
@@ -32,8 +35,7 @@ dependencies:
|
|
32
35
|
- 3
|
33
36
|
- 0
|
34
37
|
version: 1.3.0
|
35
|
-
|
36
|
-
version_requirements: *id001
|
38
|
+
requirement: *id001
|
37
39
|
description: Rails drop in for Varnish support.
|
38
40
|
email: russ@bashme.org
|
39
41
|
executables: []
|
@@ -44,18 +46,21 @@ extra_rdoc_files:
|
|
44
46
|
- LICENSE
|
45
47
|
- README.rdoc
|
46
48
|
files:
|
49
|
+
- .bundle/config
|
47
50
|
- .document
|
48
51
|
- .gitignore
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
49
54
|
- LICENSE
|
50
55
|
- README.rdoc
|
51
56
|
- Rakefile
|
52
57
|
- VERSION
|
53
58
|
- init.rb
|
54
59
|
- lacquer.gemspec
|
55
|
-
- lib/generators/USAGE
|
56
|
-
- lib/generators/
|
57
|
-
- lib/generators/templates/initializer.rb
|
58
|
-
- lib/generators/templates/varnish.sample.vcl
|
60
|
+
- lib/generators/lacquer/USAGE
|
61
|
+
- lib/generators/lacquer/install_generator.rb
|
62
|
+
- lib/generators/lacquer/templates/initializer.rb
|
63
|
+
- lib/generators/lacquer/templates/varnish.sample.vcl
|
59
64
|
- lib/lacquer.rb
|
60
65
|
- lib/lacquer/cache_utils.rb
|
61
66
|
- lib/lacquer/configuration.rb
|
@@ -64,8 +69,9 @@ files:
|
|
64
69
|
- lib/lacquer/varnish.rb
|
65
70
|
- rails/init.rb
|
66
71
|
- spec/lacquer/cache_utils_spec.rb
|
72
|
+
- spec/lacquer/delayed_job_job_spec.rb
|
73
|
+
- spec/lacquer/resque_job_spec.rb
|
67
74
|
- spec/lacquer/varnish_spec.rb
|
68
|
-
- spec/spec.opts
|
69
75
|
- spec/spec_helper.rb
|
70
76
|
has_rdoc: true
|
71
77
|
homepage: http://github.com/russ/lacquer
|
@@ -103,5 +109,7 @@ specification_version: 3
|
|
103
109
|
summary: Rails drop in for Varnish support.
|
104
110
|
test_files:
|
105
111
|
- spec/lacquer/cache_utils_spec.rb
|
112
|
+
- spec/lacquer/delayed_job_job_spec.rb
|
113
|
+
- spec/lacquer/resque_job_spec.rb
|
106
114
|
- spec/lacquer/varnish_spec.rb
|
107
115
|
- spec/spec_helper.rb
|
data/lib/generators/USAGE
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
|
3
|
-
class LacquerGenerator < Rails::Generators::NamedBase
|
4
|
-
source_root File.expand_path('../templates', __FILE__)
|
5
|
-
|
6
|
-
def install
|
7
|
-
copy_file('varnish.sample.vcl', 'config/varnish.sample.vcl')
|
8
|
-
copy_file('initializer.rb', 'config/initializers/lacquer.rb')
|
9
|
-
end
|
10
|
-
end
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|