Rails 7 ActiveSupport::Cache::MemCacheStore now accepts an explicit nil for addresses argument

For those using Dalli as cache store in Rails, this config should appear somewhat familiar:

config.cache_store = :dalli_cache, nil, { expires_in: 1.hour }

In the above code snippet, we passed nil for the addresses argument. But if we were to migrate to :mem_cache_store with the same config like below:

config.cache_store = :mem_cache_store, nil, { expires_in: 1.hour }

then the value of addresses would be [nil] instead of nil causing an exception when trying to access the cache.

> Rails.cache.fetch('user_id')
NoMethodError: undefined method `match' for nil:NilClass

Rails 7

This PR adds support for passing an explicit nil to mem_cache_store. This change makes migrating from :dalli_store to :mem_cache_store easier.

After this change, below config:

config.cache_store = :mem_cache_store, nil

would be equivalent to

config.cache_store = :mem_cache_store  # implicit nil for addresses

Need help on your Ruby on Rails or React project?

Join Our Newsletter