lacquer 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lacquer.gemspec +4 -3
- data/lib/generators/USAGE +5 -0
- data/lib/generators/lacquer_generator.rb +3 -5
- data/lib/generators/templates/initializer.rb +10 -1
- data/lib/lacquer.rb +1 -1
- data/lib/lacquer/cache_utils.rb +3 -3
- data/lib/lacquer/delayed_job_job.rb +5 -3
- data/lib/lacquer/resque_job.rb +7 -5
- data/lib/lacquer/{varnish_interface.rb → varnish.rb} +21 -3
- data/test/test_cache_utils.rb +3 -1
- data/test/test_varnish_interface.rb +2 -2
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
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.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Russ Smith"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-14}
|
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 = [
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"VERSION",
|
26
26
|
"init.rb",
|
27
27
|
"lacquer.gemspec",
|
28
|
+
"lib/generators/USAGE",
|
28
29
|
"lib/generators/lacquer_generator.rb",
|
29
30
|
"lib/generators/templates/initializer.rb",
|
30
31
|
"lib/generators/templates/varnish.sample.vcl",
|
@@ -33,7 +34,7 @@ Gem::Specification.new do |s|
|
|
33
34
|
"lib/lacquer/configuration.rb",
|
34
35
|
"lib/lacquer/delayed_job_job.rb",
|
35
36
|
"lib/lacquer/resque_job.rb",
|
36
|
-
"lib/lacquer/
|
37
|
+
"lib/lacquer/varnish.rb",
|
37
38
|
"rails/init.rb",
|
38
39
|
"test/helper.rb",
|
39
40
|
"test/test_cache_utils.rb",
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'rails/generators'
|
2
2
|
|
3
|
-
class LacquerGenerator < Rails::Generators::
|
4
|
-
|
5
|
-
File.join(File.dirname(__FILE__), 'templates')
|
6
|
-
end
|
3
|
+
class LacquerGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
5
|
|
8
|
-
def
|
6
|
+
def install
|
9
7
|
copy_file('varnish.sample.vcl', 'config/varnish.sample.vcl')
|
10
8
|
copy_file('initializer.rb', 'config/initializers/lacquer.rb')
|
11
9
|
end
|
@@ -1,6 +1,15 @@
|
|
1
1
|
Lacquer.configure do |config|
|
2
|
+
# Globally enable/disable cache
|
2
3
|
config.enable_cache = true
|
4
|
+
|
5
|
+
# Unless overridden in a controller or action, the default will be used
|
3
6
|
config.default_ttl = 1.week
|
7
|
+
|
8
|
+
# Can be :none, :delayed_job, :resque
|
4
9
|
config.job_backend = :none
|
5
|
-
|
10
|
+
|
11
|
+
# Array of Varnish servers to manage
|
12
|
+
config.varnish_servers << {
|
13
|
+
:host => '0.0.0.0', :port => 6082
|
14
|
+
}
|
6
15
|
end
|
data/lib/lacquer.rb
CHANGED
data/lib/lacquer/cache_utils.rb
CHANGED
@@ -28,12 +28,12 @@ module Lacquer
|
|
28
28
|
case Lacquer.configuration.job_backend
|
29
29
|
when :delayed_job
|
30
30
|
require 'lacquer/delayed_job_job'
|
31
|
-
Delayed::Job.enqueue(DelayedJobJob.new('url.purge ' << path))
|
31
|
+
Delayed::Job.enqueue(Lacquer::DelayedJobJob.new('url.purge ' << path))
|
32
32
|
when :resque
|
33
33
|
require 'lacquer/resque_job'
|
34
|
-
Resque.enqueue(ResqueJob, 'url.purge ' << path)
|
34
|
+
Resque.enqueue(Lacquer::ResqueJob, 'url.purge ' << path)
|
35
35
|
when :none
|
36
|
-
|
36
|
+
Varnish.new.purge('url.purge ' << path)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
data/lib/lacquer/resque_job.rb
CHANGED
@@ -1,14 +1,32 @@
|
|
1
1
|
module Lacquer
|
2
|
-
class
|
2
|
+
class Varnish
|
3
|
+
def stats
|
4
|
+
stats = send_command('stats').split("\n")
|
5
|
+
stats.shift
|
6
|
+
|
7
|
+
stats = stats.collect do |stat|
|
8
|
+
stat = stat.strip.match(/(\d+)\s+(.+)$/)
|
9
|
+
{ :key => stat[2], :value => stat[1] }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def purge(path)
|
14
|
+
(send_command('url.purge ' << path) == '200 0') ? true : false
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
3
19
|
# Sends commands over telnet to varnish servers listed in the config.
|
4
|
-
def
|
20
|
+
def send_command(command)
|
5
21
|
Lacquer.configuration.varnish_servers.each do |server|
|
6
22
|
begin
|
7
23
|
connection = Net::Telnet.new(
|
8
24
|
'Host' => server[:host],
|
9
25
|
'Port' => server[:port],
|
10
26
|
'Timeout' => server[:timeout] || 5)
|
11
|
-
connection.
|
27
|
+
connection.cmd(command) do |c|
|
28
|
+
return c.strip
|
29
|
+
end
|
12
30
|
rescue Exception => e
|
13
31
|
raise VarnishError.new("Error while trying to connect to #{server[:host]}:#{server[:port]} #{e}")
|
14
32
|
end
|
data/test/test_cache_utils.rb
CHANGED
@@ -7,8 +7,10 @@ class TestLacquer < ActiveSupport::TestCase
|
|
7
7
|
|
8
8
|
context "when job backend is :none" do
|
9
9
|
should "take paths to clear cache for" do
|
10
|
+
varnish_stub = mock('Varnish')
|
11
|
+
Lacquer::Varnish.stubs('new').returns(varnish_stub)
|
12
|
+
varnish_stub.expects(:purge).twice
|
10
13
|
Lacquer.configuration.job_backend = :none
|
11
|
-
Lacquer::VarnishInterface.expects(:send_command).twice
|
12
14
|
@controller.clear_cache_for('/', '/blog/posts')
|
13
15
|
end
|
14
16
|
end
|
@@ -15,7 +15,7 @@ class TestLacquer < ActiveSupport::TestCase
|
|
15
15
|
context "when connection is succesful" do
|
16
16
|
should "send command to varnish server" do
|
17
17
|
Net::Telnet.stubs(:new).returns(@telnet_mock)
|
18
|
-
Lacquer::
|
18
|
+
Lacquer::Varnish.new.purge('/')
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -23,7 +23,7 @@ class TestLacquer < ActiveSupport::TestCase
|
|
23
23
|
should "raise timeout exception" do
|
24
24
|
Net::Telnet.stubs(:new).raises(Timeout::Error)
|
25
25
|
assert_raise Lacquer::VarnishError do
|
26
|
-
Lacquer::
|
26
|
+
Lacquer::Varnish.new.purge('/')
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Russ Smith
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-14 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- VERSION
|
37
37
|
- init.rb
|
38
38
|
- lacquer.gemspec
|
39
|
+
- lib/generators/USAGE
|
39
40
|
- lib/generators/lacquer_generator.rb
|
40
41
|
- lib/generators/templates/initializer.rb
|
41
42
|
- lib/generators/templates/varnish.sample.vcl
|
@@ -44,7 +45,7 @@ files:
|
|
44
45
|
- lib/lacquer/configuration.rb
|
45
46
|
- lib/lacquer/delayed_job_job.rb
|
46
47
|
- lib/lacquer/resque_job.rb
|
47
|
-
- lib/lacquer/
|
48
|
+
- lib/lacquer/varnish.rb
|
48
49
|
- rails/init.rb
|
49
50
|
- test/helper.rb
|
50
51
|
- test/test_cache_utils.rb
|