lib/mobility/backends/table.rb in mobility-0.8.13 vs lib/mobility/backends/table.rb in mobility-1.0.0.alpha

- old
+ new

@@ -63,11 +63,10 @@ @see Mobility::Backends::ActiveRecord::Table @see Mobility::Backends::Sequel::Table =end module Table - extend Backend::OrmDelegator # @!method association_name # Returns the name of the translations association. # @return [Symbol] Name of the association # @!method subclass_name @@ -132,24 +131,33 @@ end # Simple hash cache to memoize translations as a hash so they can be # fetched quickly. module Cache - include Plugins::Cache::TranslationCacher.new(:translation_for) + def translation_for(locale, **options) + return super(locale, options) if options.delete(:cache) == false + if cache.has_key?(locale) + cache[locale] + else + cache[locale] = super(locale, options) + end + end + def clear_cache + model_cache && model_cache.clear + end + private def cache model_cache || model.instance_variable_set(:"@__mobility_#{association_name}_cache", {}) end def model_cache model.instance_variable_get(:"@__mobility_#{association_name}_cache") end - - def clear_cache - model_cache && model_cache.clear - end end end + + register_backend(:table, Table) end end