Module: Mobility::Backends::Table::Cache

Defined in:
lib/mobility/backends/table.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#clear_cacheObject



143
144
145
# File 'lib/mobility/backends/table.rb', line 143

def clear_cache
  cache.clear
end

#translation_for(locale, **options) ⇒ Object



134
135
136
137
138
139
140
141
# 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