Module: Mobility::Plugins::Cache::BackendMethods

Defined in:
lib/mobility/plugins/cache.rb

Backend Accessors collapse

Instance Method Summary collapse

Instance Method Details

#clear_cacheObject



82
83
84
# File 'lib/mobility/plugins/cache.rb', line 82

def clear_cache
  @cache = {}
end

#read(locale, value, options = {}) ⇒ Object

Gets the translated value for provided locale from configured backend.

Parameters:

  • locale (Symbol)

    Locale to read

Returns:

  • (Object)

    Value of translation



64
65
66
67
68
69
70
71
# File 'lib/mobility/plugins/cache.rb', line 64

def read(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

#write(locale, value, **options) ⇒ Object

Updates translation for provided locale without calling backend’s methods to persist the changes.

Parameters:

  • locale (Symbol)

    Locale to write

  • value (Object)

    Value to write

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • cache (Boolean)

    false to disable cache.

Returns:

  • (Object)

    Updated value



76
77
78
79
# File 'lib/mobility/plugins/cache.rb', line 76

def write(locale, value, **options)
  return super if options.delete(:cache) == false
  cache[locale] = super
end