Skip to content

Commit

Permalink
Merge pull request #7838 from guilleiguaran/extract-rack-cache
Browse files Browse the repository at this point in the history
Disable Rack::Cache by default
  • Loading branch information
spastorino committed Oct 5, 2012
2 parents 4b33bbc + ab4c079 commit a8c8a08
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
10 changes: 7 additions & 3 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##

* The `Rack::Cache` middleware is now disabled by default. To enable it,
set `config.action_dispatch.rack_cache = true` and add `gem rack-cache` to your Gemfile.

*Guillermo Iguaran*

* `ActionController::Base.page_cache_extension` option is deprecated
in favour of `ActionController::Base.default_static_extension`.

Expand All @@ -13,10 +18,9 @@

* Failsafe exception returns text/plain. *Steve Klabnik*

* Remove actionpack's rack-cache dependency and declare the
dependency in the Gemfile.
* Remove `rack-cache` dependency from Action Pack and declare it on Gemfile

*Guillermo Iguarán*
*Guillermo Iguaran*

* Rename internal variables on ActionController::TemplateAssertions to prevent
naming collisions. @partials, @templates and @layouts are now prefixed with an underscore.
Expand Down
7 changes: 1 addition & 6 deletions actionpack/lib/action_dispatch/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ class Railtie < Rails::Railtie
config.action_dispatch.rescue_templates = { }
config.action_dispatch.rescue_responses = { }
config.action_dispatch.default_charset = nil

config.action_dispatch.rack_cache = {
:metastore => "rails:/",
:entitystore => "rails:/",
:verbose => false
}
config.action_dispatch.rack_cache = false

config.action_dispatch.default_headers = {
'X-Frame-Options' => 'SAMEORIGIN',
Expand Down
9 changes: 9 additions & 0 deletions railties/lib/rails/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ def default_middleware_stack #:nodoc:
error.message << ' Be sure to add rack-cache to your Gemfile'
raise
end

if rack_cache == true
rack_cache = {
:metastore => "rails:/",
:entitystore => "rails:/",
:verbose => false
}
end

require "action_dispatch/http/rack_cache"
middleware.use ::Rack::Cache, rack_cache
end
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/generators/rails/app/templates/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ source 'https://rubygems.org'
<%= javascript_gemfile_entry %>
# Puts a simple HTTP cache in front of your app (and gets you ready for later upgrading to nginx/varnish/squid)
gem 'rack-cache', '~> 1.2'
# gem 'rack-cache', '~> 1.2'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true

# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false

Expand Down
11 changes: 10 additions & 1 deletion railties/test/application/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ def app
assert !middleware.include?("Rack::Sendfile"), "Rack::Sendfile is not included in the default stack unless you set config.action_dispatch.x_sendfile_header"
end

test "Rack::Cache is present when action_controller.perform_caching is set" do
test "Rack::Cache is not included by default" do
add_to_config "config.action_controller.perform_caching = true"

boot!

assert !middleware.include?("Rack::Cache"), "Rack::Cache is not included in the default stack unless you set config.action_dispatch.rack_cache"
end

test "Rack::Cache is present when action_controller.perform_caching is set and action_dispatch.rack_cache is set" do
add_to_config "config.action_controller.perform_caching = true"
add_to_config "config.action_dispatch.rack_cache = true"

boot!

assert_equal "Rack::Cache", middleware.first
end

Expand Down

0 comments on commit a8c8a08

Please sign in to comment.