Permalink
Browse files

speedup cache_key

  • Loading branch information...
1 parent 408499c commit d7c869a4039b3adcf89ace8ca83a4f301ff22e03 @lawrencepit lawrencepit committed with josevalim Aug 3, 2010
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/i18n/backend/cache.rb
@@ -84,11 +84,15 @@ def fetch(cache_key, &block)
def cache_key(locale, key, options)
# This assumes that only simple, native Ruby values are passed to I18n.translate.
- # Also, in Ruby < 1.8.7 {}.hash != {}.hash
- # (see http://paulbarry.com/articles/2009/09/14/why-rails-3-will-require-ruby-1-8-7)
- # If args.inspect does not work for you for some reason, patches are very welcome :)
- ['i18n', I18n.cache_namespace, locale, key.hash, RUBY_VERSION >= "1.8.7" ? options.hash : options.inspect.hash].join('/')
+ "i18n/#{I18n.cache_namespace}/#{locale}/#{key.hash}/#{HASH_HASH ? options.hash : options.inspect.hash}"
end
+
+ private
+ # In Ruby < 1.8.7 {}.hash != {}.hash
+ # (see http://paulbarry.com/articles/2009/09/14/why-rails-3-will-require-ruby-1-8-7)
+ # If options.inspect.hash does not work for you for some reason, patches are very welcome :)
+ HASH_HASH = RUBY_VERSION >= "1.8.7"
+
end
end
end

0 comments on commit d7c869a

Please sign in to comment.