Skip to content

Commit

Permalink
Simplify lookup_store
Browse files Browse the repository at this point in the history
This fixes a regression #38532 caused by f9633cd.

Closes #38532.
  • Loading branch information
kamipo committed Feb 24, 2020
1 parent 9184c12 commit 5813aac
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/abstract_controller/caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def cache_store
end

def cache_store=(store)
config.cache_store = ActiveSupport::Cache.lookup_store(store)
config.cache_store = ActiveSupport::Cache.lookup_store(*store)
end

private
Expand Down
7 changes: 3 additions & 4 deletions activesupport/lib/active_support/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ class << self
#
# ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new)
# # => returns MyOwnCacheStore.new
def lookup_store(*store_args, **store_options)
store, *parameters = *Array.wrap(store_args).flatten

def lookup_store(store = nil, *parameters)
case store
when Symbol
retrieve_store_class(store).new(*parameters, **store_options)
options = parameters.extract_options!
retrieve_store_class(store).new(*parameters, **options)
when nil
ActiveSupport::Cache::MemoryStore.new
else
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/application/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module Bootstrap
# Initialize cache early in the stack so railties can make use of it.
initializer :initialize_cache, group: :all do
unless Rails.cache
Rails.cache = ActiveSupport::Cache.lookup_store(config.cache_store)
Rails.cache = ActiveSupport::Cache.lookup_store(*config.cache_store)

if Rails.cache.respond_to?(:middleware)
config.middleware.insert_before(::Rack::Runtime, Rails.cache.middleware)
Expand Down
3 changes: 2 additions & 1 deletion railties/test/application/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,10 @@ def app
end

test "Rails.cache does not respond to middleware" do
add_to_config "config.cache_store = :memory_store"
add_to_config "config.cache_store = :memory_store, { timeout: 10 }"
boot!
assert_equal "Rack::Runtime", middleware[5]
assert_instance_of ActiveSupport::Cache::MemoryStore, Rails.cache
end

test "Rails.cache does respond to middleware" do
Expand Down

0 comments on commit 5813aac

Please sign in to comment.