Skip to content

Commit

Permalink
Remove old code for Ruby < 1.9
Browse files Browse the repository at this point in the history
Ruby 2.3 is the oldest Ruby we support now. We can remove this check.
  • Loading branch information
radar committed Jan 6, 2019
1 parent 28d6996 commit bd3b486
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions lib/i18n/backend/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,7 @@ def _fetch(cache_key, &block)

def cache_key(locale, key, options)
# This assumes that only simple, native Ruby values are passed to I18n.translate.
"i18n/#{I18n.cache_namespace}/#{locale}/#{digest_item(key)}/#{USE_INSPECT_HASH ? digest_item(options.inspect) : digest_item(options)}"
end

private
# In Ruby < 1.9 the following is true: { :foo => 1, :bar => 2 }.hash == { :foo => 2, :bar => 1 }.hash
# Therefore we must use the hash of the inspect string instead to avoid cache key colisions.
USE_INSPECT_HASH = RUBY_VERSION <= "1.9"

def digest_item(key)
I18n.cache_key_digest ? I18n.cache_key_digest.hexdigest(key.to_s) : key.hash
"i18n/#{I18n.cache_namespace}/#{locale}/#{digest_item(key)}/#{digest_item(options)}"
end
end
end
Expand Down

0 comments on commit bd3b486

Please sign in to comment.