Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow addresses to support nil values #41381

Merged
merged 1 commit into from Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions activesupport/CHANGELOG.md
@@ -1,3 +1,23 @@
* `ActiveSupport::Cache::MemCacheStore` now accepts an explicit `nil` for its `addresses` argument.

```ruby
config.cache_store = :mem_cache_store, nil

# is now equivalent to

config.cache_store = :mem_cache_store

# and is also equivalent to

config.cache_store = :mem_cache_store, ENV["MEMCACHE_SERVERS"] || "localhost:11211"

# which is the fallback behavior of Dalli
```

This helps those migrating from `:dalli_store`, where an explicit `nil` was permitted.

*Michael Overmeyer*

* Add `Enumerable#in_order_of` to put an Enumerable in a certain order by a key.

*DHH*
Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/cache/mem_cache_store.rb
Expand Up @@ -64,7 +64,7 @@ def self.supports_cache_versioning?
def self.build_mem_cache(*addresses) # :nodoc:
addresses = addresses.flatten
options = addresses.extract_options!
addresses = nil if addresses.empty?
addresses = nil if addresses.compact.empty?
pool_options = retrieve_pool_options(options)

if pool_options.empty?
Expand Down
8 changes: 8 additions & 0 deletions activesupport/test/cache/stores/mem_cache_store_test.rb
Expand Up @@ -197,6 +197,14 @@ def test_falls_back_to_localhost_if_no_address_provided_and_memcache_servers_und
end
end

def test_falls_back_to_localhost_if_address_provided_as_nil
with_memcache_servers_environment_variable(nil) do
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, nil)

assert_equal ["127.0.0.1:11211"], servers(cache)
end
end

def test_falls_back_to_localhost_if_no_address_provided_and_memcache_servers_defined
with_memcache_servers_environment_variable("custom_host") do
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store)
Expand Down