module Mobility::Backends::Table::Cache

Simple hash cache to memoize translations as a hash so they can be fetched quickly.

Public Instance Methods

clear_cache() click to toggle source
# File lib/mobility/backends/table.rb, line 143
def clear_cache
  cache.clear
end
translation_for(locale, **options) click to toggle source
Calls superclass method
# File lib/mobility/backends/table.rb, line 134
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

Private Instance Methods

cache() click to toggle source
# File lib/mobility/backends/table.rb, line 149
def cache
  if model.instance_variable_defined?(cache_name)
    model.instance_variable_get(cache_name)
  else
    model.instance_variable_set(cache_name, {})
  end
end
cache_name() click to toggle source
# File lib/mobility/backends/table.rb, line 157
def cache_name
  @cache_name ||= :"@__mobility_#{association_name}_cache"
end