Class: I18n::Backend::CachedKeyValueStore

Inherits:
KeyValue
  • Object
show all
Includes:
Memoize
Defined in:
lib/i18n/backend/cached_key_value_store.rb

Constant Summary collapse

KEY_PREFIX =
'i18n:locale_version:'

Instance Method Summary collapse

Instance Method Details

#current_version(locale) ⇒ Object



31
32
33
# File 'lib/i18n/backend/cached_key_value_store.rb', line 31

def current_version(locale)
  @store["#{KEY_PREFIX}#{locale}"]
end

#ensure_freshness!(locale) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/i18n/backend/cached_key_value_store.rb', line 13

def ensure_freshness!(locale)
  current = current_version locale

  if last_version[locale] != current
    reset_memoizations! locale
    last_version[locale] = current
  end
end

#last_versionObject



22
23
24
# File 'lib/i18n/backend/cached_key_value_store.rb', line 22

def last_version
  @last_version ||= {}
end

#on_update_version(locale = nil, &block) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/i18n/backend/cached_key_value_store.rb', line 35

def on_update_version(locale = nil, &block)
  if block_given?
    @on_store_block = block
  elsif @on_store_block != nil
    @on_store_block.call locale
  end
end

#store_translations(locale, data, options = {}) ⇒ Object



8
9
10
11
# File 'lib/i18n/backend/cached_key_value_store.rb', line 8

def store_translations(locale, data, options = {})
  update_version! locale
  super
end

#update_version!(locale) ⇒ Object



26
27
28
29
# File 'lib/i18n/backend/cached_key_value_store.rb', line 26

def update_version!(locale)
  @store["#{KEY_PREFIX}#{locale}"] = Time.now.to_i
  on_update_version locale
end