Skip to content

Commit

Permalink
Remove hash allocation in Store#namespace_key
Browse files Browse the repository at this point in the history
Previously, every call to `namespace_key` would merge the options given
with the Store's default options. This unnecessarily allocates a new
hash when all `namespace_key` needs is the `namespace` option.

This commit removes the allocation by simply checking the default
options after checking that the passed options do not contain a
`namespace` key.
  • Loading branch information
skipkayhil committed Sep 21, 2024
1 parent 34ea0a5 commit b87e1e6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions activesupport/lib/active_support/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -945,9 +945,12 @@ def normalize_key(key, options = nil)
#
# namespace_key 'foo', namespace: -> { 'cache' }
# # => 'cache:foo'
def namespace_key(key, options = nil)
options = merged_options(options)
namespace = options[:namespace]
def namespace_key(key, call_options = nil)
namespace = if call_options&.key?(:namespace)
call_options[:namespace]
else
options[:namespace]
end

if namespace.respond_to?(:call)
namespace = namespace.call
Expand Down

0 comments on commit b87e1e6

Please sign in to comment.