Module: SgtnClient::TranslationLoader::Cache

Defined in:
lib/sgtn-client/loader/cache.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#available_bundlesObject



25
26
27
28
29
30
31
# File 'lib/sgtn-client/loader/cache.rb', line 25

def available_bundles
  SgtnClient.logger.debug { "[#{__FILE__}][#{__callee__}]" }

  result = @cache_hash[CONSTS::AVAILABLE_BUNDLES_KEY] || super
ensure
  super(sync: false) if result&.expired?
end

#get_bundle(component, locale) ⇒ Object

get from cache, return expired data immediately



17
18
19
20
21
22
23
# File 'lib/sgtn-client/loader/cache.rb', line 17

def get_bundle(component, locale)
  SgtnClient.logger.debug { "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}" }

  result = @cache_hash[Common::BundleID.new(component, locale)] || load_bundle(component, locale)
ensure
  load_bundle(component, locale, sync: false) if result&.expired?
end

#initializeObject



11
12
13
14
# File 'lib/sgtn-client/loader/cache.rb', line 11

def initialize(*)
  @cache_hash = Concurrent::Map.new
  super
end