Class: Mobility::Plugins::Cache::TranslationCacher
- Inherits:
-
Module
- Object
- Module
- Mobility::Plugins::Cache::TranslationCacher
- Defined in:
- lib/mobility/plugins/cache/translation_cacher.rb
Overview
Creates a module to cache a given translation fetch method. The cacher defines
private methods cache and clear_cache to access and clear, respectively, a
translations hash.
This cacher is used to cache translation values in Mobility::Plugins::Cache, and also to cache translation records in Backends::Table and Backends::KeyValue.
Instance Method Summary collapse
-
#initialize(fetch_method) ⇒ TranslationCacher
constructor
A new instance of TranslationCacher.
Constructor Details
#initialize(fetch_method) ⇒ TranslationCacher
Returns a new instance of TranslationCacher.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mobility/plugins/cache/translation_cacher.rb', line 17 def initialize(fetch_method) define_method fetch_method do |locale, **| return super(locale, ) if .delete(:cache) == false if cache.has_key?(locale) cache[locale] else cache[locale] = super(locale, ) end end define_method :cache do @cache ||= {} end define_method :clear_cache do @cache = {} end private :cache, :clear_cache end |