radiant-lacquer-extension 1.0.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.md +75 -0
- data/Rakefile +109 -0
- data/config/initializers/radiant_config.rb +3 -0
- data/config/locales/en.yml +3 -0
- data/config/routes.rb +5 -0
- data/cucumber.yml +1 -0
- data/features/support/env.rb +11 -0
- data/features/support/paths.rb +22 -0
- data/lacquer_extension.rb +19 -0
- data/lib/lacquer/resource_controller_extension.rb +34 -0
- data/lib/lacquer/site_controller_extension.rb +1 -0
- data/lib/radiant-lacquer-extension.rb +8 -0
- data/lib/tasks/lacquer.rake +37 -0
- data/lib/tasks/lacquer_extension_tasks.rake +34 -0
- data/lib/templates/lacquer.rb +22 -0
- data/lib/templates/varnish.vcl.erb +129 -0
- data/lib/templates/varnishd.yml +27 -0
- data/radiant-lacquer-extension.gemspec +27 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +36 -0
- metadata +81 -0
data/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Radiant Lacquer Extension
|
|
2
|
+
|
|
3
|
+
Lacquer support for Radiant CMS.
|
|
4
|
+
|
|
5
|
+
The Lacquer extension uses the [Lacquer gem][lacquer] to send purge commands to Varnish. As Lacquer requires Ruby 1.9, so does this extension.
|
|
6
|
+
|
|
7
|
+
Please file bugs and feature requests on [Github][issues].
|
|
8
|
+
|
|
9
|
+
[issues]: https://github.com/jomz/radiant-lacquer-extension/issues
|
|
10
|
+
[lacquer]: https://github.com/russ/lacquer
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Add this gem via bundler:
|
|
15
|
+
|
|
16
|
+
gem 'radiant-lacquer-extension' && bundle install
|
|
17
|
+
|
|
18
|
+
Run `rake radiant:extensions:lacquer:update`. This will add the following files:
|
|
19
|
+
|
|
20
|
+
* RAILS_ROOT/config/varnishd.yml
|
|
21
|
+
* RAILS_ROOT/config/varnishd.vcl.erb
|
|
22
|
+
* RAILS_ROOT/config/initializers/lacquer.rb
|
|
23
|
+
|
|
24
|
+
You will want to update lacquer.rb and varnishd.yml
|
|
25
|
+
Installation of Varnish itself is not covered in this README.
|
|
26
|
+
|
|
27
|
+
## Purge strategy
|
|
28
|
+
|
|
29
|
+
This extension hooks into Admin::ResourceController to send purge commands through Lacquer. For any model class except Page, a global purge is performed after every CUD (create update destroy) action.
|
|
30
|
+
|
|
31
|
+
For pages, a CUD action will purge the cache for that page, all it's descendants, all it's ancestors and their descendants, except for the home page's descendants.
|
|
32
|
+
|
|
33
|
+
Assuming these pages exist in the cache:
|
|
34
|
+
|
|
35
|
+
/
|
|
36
|
+
/about
|
|
37
|
+
/about/team
|
|
38
|
+
/about/team/freelancers
|
|
39
|
+
/about/contact
|
|
40
|
+
/blog
|
|
41
|
+
/blog/2012/01/12/varnish-is-so-awesome
|
|
42
|
+
/portfolio
|
|
43
|
+
|
|
44
|
+
An update to /about/team will purge the following pages;
|
|
45
|
+
|
|
46
|
+
/about/team
|
|
47
|
+
/about/team/freelancers (because it's a descendant of /about/team)
|
|
48
|
+
/about (because it's an ancestor of /about/team)
|
|
49
|
+
/about/contact (because it's a descendant of /about)
|
|
50
|
+
/ (because it's the home page)
|
|
51
|
+
|
|
52
|
+
But leave the cache for /blog and /portfolio alone. The idea is to avoid unnecessary purging. This strategy may not be 100% fit for your site.
|
|
53
|
+
For example if on /portfolio you render content from /about (e.g. via r:find), this page will be stale, but not purged.
|
|
54
|
+
To overwrite this behavior, you will want to change clear\_model\_cache\_with\_lacquer in Admin::ResourceController.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## Contributions
|
|
58
|
+
|
|
59
|
+
If you would like to contribute, please [fork the project][fork] and submit a [pull request][pull-request].
|
|
60
|
+
|
|
61
|
+
[fork]: http://help.github.com/fork-a-repo/
|
|
62
|
+
[pull-request]: http://help.github.com/send-pull-requests/
|
|
63
|
+
|
|
64
|
+
Pull requests with working tests are preferred and have a greater chance of being merged.
|
|
65
|
+
|
|
66
|
+
## TODO
|
|
67
|
+
|
|
68
|
+
* Add tests!
|
|
69
|
+
* Make purge strategy configurable
|
|
70
|
+
|
|
71
|
+
## Authors
|
|
72
|
+
|
|
73
|
+
* Benny Degezelle
|
|
74
|
+
|
|
75
|
+
Released under the same terms as Radiant.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Determine where the RSpec plugin is by loading the boot
|
|
2
|
+
unless defined? RADIANT_ROOT
|
|
3
|
+
ENV["RAILS_ENV"] = "test"
|
|
4
|
+
case
|
|
5
|
+
when ENV["RADIANT_ENV_FILE"]
|
|
6
|
+
require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
|
|
7
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
|
8
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
|
9
|
+
else
|
|
10
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
require 'rake'
|
|
15
|
+
require 'rdoc/task'
|
|
16
|
+
require 'rake/testtask'
|
|
17
|
+
|
|
18
|
+
rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
|
|
19
|
+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
|
20
|
+
require 'spec/rake/spectask'
|
|
21
|
+
require 'cucumber'
|
|
22
|
+
require 'cucumber/rake/task'
|
|
23
|
+
|
|
24
|
+
# Cleanup the RADIANT_ROOT constant so specs will load the environment
|
|
25
|
+
Object.send(:remove_const, :RADIANT_ROOT)
|
|
26
|
+
|
|
27
|
+
extension_root = File.expand_path(File.dirname(__FILE__))
|
|
28
|
+
|
|
29
|
+
task :default => [:spec, :features]
|
|
30
|
+
task :stats => "spec:statsetup"
|
|
31
|
+
|
|
32
|
+
desc "Run all specs in spec directory"
|
|
33
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
|
34
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
|
35
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
task :features => 'spec:integration'
|
|
39
|
+
|
|
40
|
+
namespace :spec do
|
|
41
|
+
desc "Run all specs in spec directory with RCov"
|
|
42
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
|
43
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
|
44
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
|
45
|
+
t.rcov = true
|
|
46
|
+
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
desc "Print Specdoc for all specs"
|
|
50
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
|
51
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
|
52
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
[:models, :controllers, :views, :helpers].each do |sub|
|
|
56
|
+
desc "Run the specs under spec/#{sub}"
|
|
57
|
+
Spec::Rake::SpecTask.new(sub) do |t|
|
|
58
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
|
59
|
+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
desc "Run the Cucumber features"
|
|
64
|
+
Cucumber::Rake::Task.new(:integration) do |t|
|
|
65
|
+
t.fork = true
|
|
66
|
+
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
|
|
67
|
+
# t.feature_pattern = "#{extension_root}/features/**/*.feature"
|
|
68
|
+
t.profile = "default"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Setup specs for stats
|
|
72
|
+
task :statsetup do
|
|
73
|
+
require 'code_statistics'
|
|
74
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
|
|
75
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views)
|
|
76
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
|
|
77
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
|
|
78
|
+
::CodeStatistics::TEST_TYPES << "Model specs"
|
|
79
|
+
::CodeStatistics::TEST_TYPES << "View specs"
|
|
80
|
+
::CodeStatistics::TEST_TYPES << "Controller specs"
|
|
81
|
+
::CodeStatistics::TEST_TYPES << "Helper specs"
|
|
82
|
+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
namespace :db do
|
|
86
|
+
namespace :fixtures do
|
|
87
|
+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
|
88
|
+
task :load => :environment do
|
|
89
|
+
require 'active_record/fixtures'
|
|
90
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
|
91
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
|
92
|
+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
desc 'Generate documentation for the lacquer extension.'
|
|
100
|
+
RDoc:Task.new(:rdoc) do |rdoc|
|
|
101
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
102
|
+
rdoc.title = 'LacquerExtension'
|
|
103
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
|
104
|
+
rdoc.rdoc_files.include('README')
|
|
105
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Load any custom rakefiles for extension
|
|
109
|
+
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
data/config/routes.rb
ADDED
data/cucumber.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
default: --format progress features --tags ~@proposed,~@in_progress
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Sets up the Rails environment for Cucumber
|
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
|
3
|
+
# Extension root
|
|
4
|
+
extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
|
|
5
|
+
require extension_env+'.rb'
|
|
6
|
+
|
|
7
|
+
Dir.glob(File.join(RADIANT_ROOT, "features", "**", "*.rb")).each {|step| require step unless step =~ /datasets_loader\.rb$/}
|
|
8
|
+
|
|
9
|
+
Cucumber::Rails::World.class_eval do
|
|
10
|
+
dataset :lacquer
|
|
11
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module NavigationHelpers
|
|
2
|
+
|
|
3
|
+
# Extend the standard PathMatchers with your own paths
|
|
4
|
+
# to be used in your features.
|
|
5
|
+
#
|
|
6
|
+
# The keys and values here may be used in your standard web steps
|
|
7
|
+
# Using:
|
|
8
|
+
#
|
|
9
|
+
# When I go to the "lacquer" admin page
|
|
10
|
+
#
|
|
11
|
+
# would direct the request to the path you provide in the value:
|
|
12
|
+
#
|
|
13
|
+
# admin_lacquer_path
|
|
14
|
+
#
|
|
15
|
+
PathMatchers = {} unless defined?(PathMatchers)
|
|
16
|
+
PathMatchers.merge!({
|
|
17
|
+
# /lacquer/i => 'admin_lacquer_path'
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
World(NavigationHelpers)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Uncomment this if you reference any of your controllers in activate
|
|
2
|
+
# require_dependency "application_controller"
|
|
3
|
+
require "radiant-lacquer-extension"
|
|
4
|
+
|
|
5
|
+
class LacquerExtension < Radiant::Extension
|
|
6
|
+
version RadiantLacquerExtension::VERSION
|
|
7
|
+
description RadiantLacquerExtension::DESCRIPTION
|
|
8
|
+
url RadiantLacquerExtension::URL
|
|
9
|
+
|
|
10
|
+
# See your config/routes.rb file in this extension to define custom routes
|
|
11
|
+
|
|
12
|
+
extension_config do |config|
|
|
13
|
+
# config is the Radiant.configuration object
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def activate
|
|
17
|
+
Admin::ResourceController.send :include, Lacquer::ResourceControllerExtension
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Lacquer::ResourceControllerExtension
|
|
2
|
+
def self.included(clazz)
|
|
3
|
+
clazz.class_eval do
|
|
4
|
+
include Lacquer::CacheUtils
|
|
5
|
+
|
|
6
|
+
def clear_model_cache_with_lacquer
|
|
7
|
+
if model_name == 'Page'
|
|
8
|
+
if model.published_at != nil && model.published?
|
|
9
|
+
purge_page_and_ancestors(model)
|
|
10
|
+
end
|
|
11
|
+
else
|
|
12
|
+
purge_all_pages
|
|
13
|
+
end
|
|
14
|
+
clear_model_cache_without_lacquer
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
alias_method_chain :clear_model_cache, :lacquer
|
|
18
|
+
|
|
19
|
+
def purge_page_and_ancestors(page)
|
|
20
|
+
if page.path == '/'
|
|
21
|
+
Lacquer::Varnish.new.purge("^/$") # Instead of "/", which does a global purge
|
|
22
|
+
else
|
|
23
|
+
Lacquer::Varnish.new.purge(page.path)
|
|
24
|
+
end
|
|
25
|
+
purge_page_and_ancestors(page.parent) if page.parent
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def purge_all_pages
|
|
29
|
+
Lacquer::Varnish.new.purge('.*')
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# batch_page_status_update_with_lacquer
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
module RadiantLacquerExtension
|
|
2
|
+
VERSION = "1.0.0"
|
|
3
|
+
SUMMARY = "Lacquer for Radiant CMS"
|
|
4
|
+
DESCRIPTION = "Makes Radiant play nice with Varnish through Lacquer!"
|
|
5
|
+
URL = "http://github.com/jomz/radiant-lacquer-extension"
|
|
6
|
+
AUTHORS = ["Benny Degezelle"]
|
|
7
|
+
EMAIL = ["hi@monkeypatch.be"]
|
|
8
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
namespace :lacquer do
|
|
2
|
+
namespace :varnishd do
|
|
3
|
+
desc "Start varnishd daemon using Lacquer's settings"
|
|
4
|
+
task :start => :environment do
|
|
5
|
+
Lacquer::Varnishd.new.start
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
desc "Stop varnishd daemon using Lacquer's settings"
|
|
9
|
+
task :stop => :environment do
|
|
10
|
+
Lacquer::Varnishd.new.stop
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
desc "Running status of varnishd daemon using Lacquer's settings"
|
|
14
|
+
task :status => :environment do
|
|
15
|
+
if Lacquer::Varnishd.new.running?
|
|
16
|
+
puts "Varnishd is running"
|
|
17
|
+
else
|
|
18
|
+
puts "Varnishd is not running"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
desc "Restart varnishd daemon using Lacquer's settings"
|
|
23
|
+
task :restart => :environment do
|
|
24
|
+
varnishd = Lacquer::Varnishd.new
|
|
25
|
+
if varnishd.running?
|
|
26
|
+
varnishd.stop
|
|
27
|
+
sleep(1)
|
|
28
|
+
end
|
|
29
|
+
varnishd.start
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
desc "Purge ALL urls from Varnish"
|
|
33
|
+
task :global_purge => :environment do
|
|
34
|
+
Lacquer::Varnish.new.purge('.*')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
namespace :radiant do
|
|
2
|
+
namespace :extensions do
|
|
3
|
+
namespace :lacquer do
|
|
4
|
+
|
|
5
|
+
desc "Runs the migration of the Lacquer extension"
|
|
6
|
+
task :migrate => :environment do
|
|
7
|
+
require 'radiant/extension_migrator'
|
|
8
|
+
if ENV["VERSION"]
|
|
9
|
+
LacquerExtension.migrator.migrate(ENV["VERSION"].to_i)
|
|
10
|
+
Rake::Task['db:schema:dump'].invoke
|
|
11
|
+
else
|
|
12
|
+
LacquerExtension.migrator.migrate
|
|
13
|
+
Rake::Task['db:schema:dump'].invoke
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc "Copies public assets of the Lacquer to the instance public/ directory."
|
|
18
|
+
task :update => :environment do
|
|
19
|
+
is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
|
|
20
|
+
puts "Setting default initializers"
|
|
21
|
+
Dir[LacquerExtension.root + "/lib/templates/*"].reject(&is_svn_or_dir).each do |file|
|
|
22
|
+
path = file.sub(LacquerExtension.root, '')
|
|
23
|
+
if path =~ /lacquer.rb/
|
|
24
|
+
cp file, RAILS_ROOT + '/config/initializers', :verbose => false
|
|
25
|
+
elsif path =~ /varnish./
|
|
26
|
+
cp file, RAILS_ROOT + '/config', :verbose => false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Lacquer.configure do |config|
|
|
2
|
+
config.enable_cache = true
|
|
3
|
+
config.default_ttl = 12.hours
|
|
4
|
+
# Can be :none, :delayed_job, :resque
|
|
5
|
+
config.job_backend = :none
|
|
6
|
+
# Array of Varnish servers to manage
|
|
7
|
+
config.varnish_servers << {
|
|
8
|
+
:host => "127.0.0.1", :port => 6788 # if you have authentication enabled, add :secret => "your secret"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
config.retries = 5
|
|
12
|
+
|
|
13
|
+
# Varnish 3.X
|
|
14
|
+
config.purge_command = "ban.url"
|
|
15
|
+
config.pass_command = "hit_for_pass"
|
|
16
|
+
# Varnish 2.X
|
|
17
|
+
# config.purge_command = "url.purge"
|
|
18
|
+
# config.pass_command = "pass"
|
|
19
|
+
|
|
20
|
+
# Config handler (optional, if you use Hoptoad or another error tracking service)
|
|
21
|
+
# config.command_error_handler = lambda { |s| HoptoadNotifier.notify(s) }
|
|
22
|
+
end
|
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
if (req.url ~ "/admin") {
|
|
49
|
+
# Pass to Radiant
|
|
50
|
+
return (pass);
|
|
51
|
+
}
|
|
52
|
+
# Remove any Google Analytics based cookies
|
|
53
|
+
set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", "");
|
|
54
|
+
if (req.url ~ "\.(css|ico|pdf|jpg|png|js|ttf)$") {
|
|
55
|
+
unset req.http.cookie;
|
|
56
|
+
return (lookup);
|
|
57
|
+
}
|
|
58
|
+
unset req.http.Cookie;
|
|
59
|
+
unset req.http.Authorization;
|
|
60
|
+
return(lookup);
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Called when entering pipe mode
|
|
65
|
+
sub vcl_pipe {
|
|
66
|
+
# If we don't set the Connection: close header, any following
|
|
67
|
+
# requests from the client will also be piped through and
|
|
68
|
+
# left untouched by varnish. We don't want that.
|
|
69
|
+
set req.http.connection = "close";
|
|
70
|
+
return(pipe);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
# Called when the requested object has been retrieved from the
|
|
74
|
+
# backend, or the request to the backend has failed
|
|
75
|
+
sub vcl_fetch {
|
|
76
|
+
# Set the grace time
|
|
77
|
+
set beresp.grace = 1h;
|
|
78
|
+
|
|
79
|
+
# Do not cache the object if the status is not in the 200s
|
|
80
|
+
if (beresp.status >= 300) {
|
|
81
|
+
# Remove the Set-Cookie header
|
|
82
|
+
remove beresp.http.Set-Cookie;
|
|
83
|
+
return(hit_for_pass);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# Do not cache the Radiant backend
|
|
87
|
+
if (req.url ~ "\/admin" ) {
|
|
88
|
+
return(hit_for_pass);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
# Do not cache the object if the backend application does not want us to.
|
|
92
|
+
if (beresp.http.Cache-Control ~ "(no-cache|no-store|private|must-revalidate)") {
|
|
93
|
+
return(hit_for_pass);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
# Everything below here should be cached
|
|
97
|
+
|
|
98
|
+
# Remove the Set-Cookie header
|
|
99
|
+
remove beresp.http.Set-Cookie;
|
|
100
|
+
|
|
101
|
+
# Remove Radiant's X-Rack-Cache header
|
|
102
|
+
remove beresp.http.X-Rack-Cache;
|
|
103
|
+
|
|
104
|
+
# Deliver the object
|
|
105
|
+
return(deliver);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
# Called before the response is sent back to the client
|
|
109
|
+
sub vcl_deliver {
|
|
110
|
+
# Force browsers and intermediary caches to always check back with us
|
|
111
|
+
set resp.http.Cache-Control = "private, max-age=0, must-revalidate";
|
|
112
|
+
set resp.http.Pragma = "no-cache";
|
|
113
|
+
|
|
114
|
+
# Add a header to indicate a cache HIT/MISS
|
|
115
|
+
if (obj.hits > 0) {
|
|
116
|
+
set resp.http.X-Cache = "HIT";
|
|
117
|
+
} else {
|
|
118
|
+
set resp.http.X-Cache = "MISS";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
sub vcl_hash {
|
|
123
|
+
if (req.url ~ "\/^[admin]") {
|
|
124
|
+
if (req.http.Cookie) {
|
|
125
|
+
hash_data(req.http.Cookie);
|
|
126
|
+
return (hash);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
development:
|
|
2
|
+
listen: 127.0.0.1:8080
|
|
3
|
+
telnet: 127.0.0.1:6788
|
|
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:8080
|
|
10
|
+
telnet: 127.0.0.1:6788
|
|
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:6788
|
|
18
|
+
backend: backend_server:8080
|
|
19
|
+
sbin_path: /usr/local/sbin
|
|
20
|
+
storage: "file,#{Rails.root}/log/varnishd.#{Rails.env}.cache,250MB"
|
|
21
|
+
params:
|
|
22
|
+
queue_max: 2000 # Varnish 3.X
|
|
23
|
+
# overflow_max: 2000 # Varnish 2.X
|
|
24
|
+
thread_pool_add_delay: 2
|
|
25
|
+
thread_pools: 4 # <Number of cpu cores>
|
|
26
|
+
thread_pool_min: 200 # <800/number of cpu cores>
|
|
27
|
+
thread_pool_max: 4000
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "radiant-lacquer-extension"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "radiant-lacquer-extension"
|
|
7
|
+
s.version = RadiantLacquerExtension::VERSION
|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
|
9
|
+
s.authors = RadiantLacquerExtension::AUTHORS
|
|
10
|
+
s.email = RadiantLacquerExtension::EMAIL
|
|
11
|
+
s.homepage = RadiantLacquerExtension::URL
|
|
12
|
+
s.summary = RadiantLacquerExtension::SUMMARY
|
|
13
|
+
s.description = RadiantLacquerExtension::DESCRIPTION
|
|
14
|
+
|
|
15
|
+
s.add_dependency "lacquer", "~> 0.5.5"
|
|
16
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.9.1")
|
|
17
|
+
|
|
18
|
+
ignores = if File.exist?('.gitignore')
|
|
19
|
+
File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
|
|
20
|
+
else
|
|
21
|
+
[]
|
|
22
|
+
end
|
|
23
|
+
s.files = Dir['**/*'] - ignores
|
|
24
|
+
s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
|
|
25
|
+
# s.executables = Dir['bin/*'] - ignores
|
|
26
|
+
s.require_paths = ["lib"]
|
|
27
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
unless defined? RADIANT_ROOT
|
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
|
3
|
+
case
|
|
4
|
+
when ENV["RADIANT_ENV_FILE"]
|
|
5
|
+
require ENV["RADIANT_ENV_FILE"]
|
|
6
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
|
7
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
|
|
8
|
+
else
|
|
9
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
require "#{RADIANT_ROOT}/spec/spec_helper"
|
|
13
|
+
|
|
14
|
+
Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
|
|
15
|
+
|
|
16
|
+
if File.directory?(File.dirname(__FILE__) + "/matchers")
|
|
17
|
+
Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
Spec::Runner.configure do |config|
|
|
21
|
+
# config.use_transactional_fixtures = true
|
|
22
|
+
# config.use_instantiated_fixtures = false
|
|
23
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
|
24
|
+
|
|
25
|
+
# You can declare fixtures for each behaviour like this:
|
|
26
|
+
# describe "...." do
|
|
27
|
+
# fixtures :table_a, :table_b
|
|
28
|
+
#
|
|
29
|
+
# Alternatively, if you prefer to declare them only once, you can
|
|
30
|
+
# do so here, like so ...
|
|
31
|
+
#
|
|
32
|
+
# config.global_fixtures = :table_a, :table_b
|
|
33
|
+
#
|
|
34
|
+
# If you declare global fixtures, be aware that they will be declared
|
|
35
|
+
# for all of your examples, even those that don't use them.
|
|
36
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: radiant-lacquer-extension
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Benny Degezelle
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-01-12 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: lacquer
|
|
16
|
+
requirement: &2151860980 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 0.5.5
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *2151860980
|
|
25
|
+
description: Makes Radiant play nice with Varnish through Lacquer!
|
|
26
|
+
email:
|
|
27
|
+
- hi@monkeypatch.be
|
|
28
|
+
executables: []
|
|
29
|
+
extensions: []
|
|
30
|
+
extra_rdoc_files: []
|
|
31
|
+
files:
|
|
32
|
+
- config/initializers/radiant_config.rb
|
|
33
|
+
- config/locales/en.yml
|
|
34
|
+
- config/routes.rb
|
|
35
|
+
- cucumber.yml
|
|
36
|
+
- features/support/env.rb
|
|
37
|
+
- features/support/paths.rb
|
|
38
|
+
- lacquer_extension.rb
|
|
39
|
+
- lib/lacquer/resource_controller_extension.rb
|
|
40
|
+
- lib/lacquer/site_controller_extension.rb
|
|
41
|
+
- lib/radiant-lacquer-extension.rb
|
|
42
|
+
- lib/tasks/lacquer.rake
|
|
43
|
+
- lib/tasks/lacquer_extension_tasks.rake
|
|
44
|
+
- lib/templates/lacquer.rb
|
|
45
|
+
- lib/templates/varnish.vcl.erb
|
|
46
|
+
- lib/templates/varnishd.yml
|
|
47
|
+
- radiant-lacquer-extension-1.0.0.gem
|
|
48
|
+
- radiant-lacquer-extension.gemspec
|
|
49
|
+
- Rakefile
|
|
50
|
+
- README.md
|
|
51
|
+
- spec/spec.opts
|
|
52
|
+
- spec/spec_helper.rb
|
|
53
|
+
homepage: http://github.com/jomz/radiant-lacquer-extension
|
|
54
|
+
licenses: []
|
|
55
|
+
post_install_message:
|
|
56
|
+
rdoc_options: []
|
|
57
|
+
require_paths:
|
|
58
|
+
- lib
|
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
|
+
none: false
|
|
61
|
+
requirements:
|
|
62
|
+
- - ! '>='
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: 1.9.1
|
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
|
+
none: false
|
|
67
|
+
requirements:
|
|
68
|
+
- - ! '>='
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
71
|
+
requirements: []
|
|
72
|
+
rubyforge_project:
|
|
73
|
+
rubygems_version: 1.8.10
|
|
74
|
+
signing_key:
|
|
75
|
+
specification_version: 3
|
|
76
|
+
summary: Lacquer for Radiant CMS
|
|
77
|
+
test_files:
|
|
78
|
+
- spec/spec.opts
|
|
79
|
+
- spec/spec_helper.rb
|
|
80
|
+
- features/support/env.rb
|
|
81
|
+
- features/support/paths.rb
|