lacquer 0.1.0 → 0.2.0
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/README.rdoc +23 -3
- data/VERSION +1 -1
- data/lacquer.gemspec +3 -1
- data/lib/generators/templates/initializer.rb +1 -0
- data/lib/lacquer/cache_utils.rb +10 -1
- data/lib/lacquer/configuration.rb +4 -0
- data/lib/lacquer/delayed_job_job.rb +5 -0
- data/lib/lacquer/resque_job.rb +7 -0
- data/lib/lacquer/varnish_interface.rb +1 -0
- data/test/helper.rb +14 -1
- data/test/test_cache_utils.rb +22 -10
- metadata +4 -2
data/README.rdoc
CHANGED
@@ -2,9 +2,29 @@
|
|
2
2
|
|
3
3
|
Rails drop in for Varnish support.
|
4
4
|
|
5
|
-
==
|
6
|
-
|
7
|
-
|
5
|
+
== Install
|
6
|
+
Basic installation
|
7
|
+
|
8
|
+
rails generate lacquer
|
9
|
+
|
10
|
+
config/initializers/lacquer.rb
|
11
|
+
|
12
|
+
Lacquer.configure do |config|
|
13
|
+
config.enable_cache = true
|
14
|
+
config.default_ttl = 1.week
|
15
|
+
config.varnish_servers << { :host => '0.0.0.0', :port => 6082 }
|
16
|
+
end
|
17
|
+
|
18
|
+
app/controllers/application_controller.rb
|
19
|
+
|
20
|
+
class ApplicationController < ActionController::Base
|
21
|
+
include Lacquer::CacheUtils
|
22
|
+
end
|
23
|
+
|
24
|
+
== Usage
|
25
|
+
To set a custom ttl for a controller:
|
26
|
+
|
27
|
+
before_filter { |controller| controller.set_cache_ttl(15.minutes) }
|
8
28
|
|
9
29
|
== Note on Patches/Pull Requests
|
10
30
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lacquer.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{lacquer}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
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"]
|
@@ -31,6 +31,8 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/lacquer.rb",
|
32
32
|
"lib/lacquer/cache_utils.rb",
|
33
33
|
"lib/lacquer/configuration.rb",
|
34
|
+
"lib/lacquer/delayed_job_job.rb",
|
35
|
+
"lib/lacquer/resque_job.rb",
|
34
36
|
"lib/lacquer/varnish_interface.rb",
|
35
37
|
"rails/init.rb",
|
36
38
|
"test/helper.rb",
|
data/lib/lacquer/cache_utils.rb
CHANGED
@@ -25,7 +25,16 @@ module Lacquer
|
|
25
25
|
# clear_cache_for(root_path, blog_posts_path, '/other/content/*')
|
26
26
|
def clear_cache_for(*paths)
|
27
27
|
paths.each do |path|
|
28
|
-
|
28
|
+
case Lacquer.configuration.job_backend
|
29
|
+
when :delayed_job
|
30
|
+
require 'lacquer/delayed_job_job'
|
31
|
+
Delayed::Job.enqueue(DelayedJobJob.new('url.purge ' << path))
|
32
|
+
when :resque
|
33
|
+
require 'lacquer/resque_job'
|
34
|
+
Resque.enqueue(ResqueJob, 'url.purge ' << path)
|
35
|
+
when :none
|
36
|
+
VarnishInterface.send_command('url.purge ' << path)
|
37
|
+
end
|
29
38
|
end
|
30
39
|
end
|
31
40
|
|
@@ -11,10 +11,14 @@ module Lacquer
|
|
11
11
|
# Application default ttl
|
12
12
|
attr_accessor :default_ttl
|
13
13
|
|
14
|
+
# Job Backend
|
15
|
+
attr_accessor :job_backend
|
16
|
+
|
14
17
|
def initialize
|
15
18
|
@enable_cache = true
|
16
19
|
@varnish_servers = []
|
17
20
|
@default_ttl = 1.week
|
21
|
+
@job_backend = :none
|
18
22
|
end
|
19
23
|
|
20
24
|
# Returns a hash of all configurable options
|
data/test/helper.rb
CHANGED
@@ -7,5 +7,18 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
7
7
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
8
|
require 'lacquer'
|
9
9
|
|
10
|
-
class
|
10
|
+
class ControllerClass
|
11
|
+
def self.before_filter(arg); end
|
12
|
+
def self.after_filter(arg); end
|
13
|
+
|
14
|
+
include Lacquer::CacheUtils
|
15
|
+
end
|
16
|
+
|
17
|
+
module Delayed;
|
18
|
+
module Job; end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Resque; end
|
22
|
+
|
23
|
+
class ActiveSupport::TestCase
|
11
24
|
end
|
data/test/test_cache_utils.rb
CHANGED
@@ -1,20 +1,32 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ControllerClass
|
4
|
-
def self.before_filter(arg); end
|
5
|
-
def self.after_filter(arg); end
|
6
|
-
|
7
|
-
include Lacquer::CacheUtils
|
8
|
-
end
|
9
|
-
|
10
3
|
class TestLacquer < ActiveSupport::TestCase
|
11
4
|
setup do
|
12
5
|
@controller = ControllerClass.new
|
13
6
|
end
|
14
7
|
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
context "when job backend is :none" do
|
9
|
+
should "take paths to clear cache for" do
|
10
|
+
Lacquer.configuration.job_backend = :none
|
11
|
+
Lacquer::VarnishInterface.expects(:send_command).twice
|
12
|
+
@controller.clear_cache_for('/', '/blog/posts')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when job backend is :delayed_job" do
|
17
|
+
should "take paths to clear cache for" do
|
18
|
+
Lacquer.configuration.job_backend = :delayed_job
|
19
|
+
Delayed::Job.expects(:enqueue).twice
|
20
|
+
@controller.clear_cache_for('/', '/blog/posts')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when job backend is :resque" do
|
25
|
+
should "take paths to clear cache for" do
|
26
|
+
Lacquer.configuration.job_backend = :resque
|
27
|
+
Resque.expects(:enqueue).twice
|
28
|
+
@controller.clear_cache_for('/', '/blog/posts')
|
29
|
+
end
|
18
30
|
end
|
19
31
|
|
20
32
|
context "when cache is enabled" do
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Russ Smith
|
@@ -42,6 +42,8 @@ files:
|
|
42
42
|
- lib/lacquer.rb
|
43
43
|
- lib/lacquer/cache_utils.rb
|
44
44
|
- lib/lacquer/configuration.rb
|
45
|
+
- lib/lacquer/delayed_job_job.rb
|
46
|
+
- lib/lacquer/resque_job.rb
|
45
47
|
- lib/lacquer/varnish_interface.rb
|
46
48
|
- rails/init.rb
|
47
49
|
- test/helper.rb
|