I18n::Backend::Cache

TODO Should the cache be cleared if new translations are stored?

Public Instance Methods

translate(*args) click to toggle source
    # File lib/i18n/backend/cache.rb, line 50
50:       def translate(*args)
51:         I18n.perform_caching? ? fetch(*args) { super } : super
52:       end

Protected Instance Methods

cache_key(*args) click to toggle source
    # File lib/i18n/backend/cache.rb, line 66
66:         def cache_key(*args)
67:           # This assumes that only simple, native Ruby values are passed to I18n.translate.
68:           # Also, in Ruby < 1.8.7 {}.hash != {}.hash
69:           # (see http://paulbarry.com/articles/2009/09/14/why-rails-3-will-require-ruby-1-8-7)
70:           # If args.inspect does not work for you for some reason, patches are very welcome :)
71:           hash = RUBY_VERSION >= "1.8.7" ? args.hash : args.inspect
72:           keys = ['i18n', I18n.cache_namespace, hash]
73:           keys.compact.join('-')
74:         end
fetch(*args, &block) click to toggle source
    # File lib/i18n/backend/cache.rb, line 56
56:         def fetch(*args, &block)
57:           result = I18n.cache_store.fetch(cache_key(*args), &block)
58:           raise result if result.is_a?(Exception)
59:           result = result.dup if result.frozen? rescue result
60:           result
61:         rescue MissingTranslationData => exception
62:           I18n.cache_store.write(cache_key(*args), exception)
63:           raise exception
64:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.