Module: Mova::ReadStrategy::Eager

Defined in:
lib/mova/read_strategy/eager.rb

Overview

This strategy is more perfomant with a remote storage, where each read results in a network roundtrip. Even if your cache or database is located on localhost, reading from a socket is much more slower than reading from memory. Instead of making one read per locale/scope fallback, we get combination of all fallbacks and make one request to the storage.

Examples:

Instantiating a translator with eager strategy

dalli = ActiveSupport::Cache::DalliStore.new("localhost:11211")
translator = Mova::Translator.new(storage: dalli)
translator.extend Mova::ReadStrategy::Eager

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#read_first(locales, key_with_scopes) ⇒ Object

Since:

  • 0.1.0



17
18
19
20
21
22
# File 'lib/mova/read_strategy/eager.rb', line 17

def read_first(locales, key_with_scopes)
  locales_with_scopes = Scope.cross_join(locales, key_with_scopes)
  results = storage.read_multi(*locales_with_scopes)
  _, value = results.find { |_, value| Mova.presence(value) }
  value
end