lib/tml/cache.rb
def warmup_from_cdn(version = nil)
      t0 = Time.now
      Tml.logger = Logger.new(STDOUT)

      Tml.logger.debug('Starting cache warmup from CDN...')
      app = Tml::Application.new(key: Tml.config.application[:key], cdn_host: Tml.config.application[:cdn_host])
      extract_version(app, version)

      Tml.logger.debug("Warming Up Version: #{Tml.cache.version}")

      application = app.api_client.get_from_cdn('application', {t: Time.now.to_i})
      Tml.cache.store(Tml::Application.cache_key, application)

      sources = app.api_client.get_from_cdn('sources', {t: Time.now.to_i}, {uncompressed: true})

      application['languages'].each do |lang|
        locale = lang['locale']
        language = app.api_client.get_from_cdn("#{locale}/language", {t: Time.now.to_i})
        Tml.cache.store(Tml::Language.cache_key(locale), language)

        sources.each do |src|
          source = app.api_client.get_from_cdn("#{locale}/sources/#{src}", {t: Time.now.to_i})
          Tml.cache.store(Tml::Source.cache_key(locale, src), source)
        end
      end

      t1 = Time.now
      Tml.logger.debug("Cache warmup took #{t1-t0}s")
    end
def warmup_from_cdn(version = nil)
      t0 = Time.now
      Tml.logger = Logger.new(STDOUT)

      Tml.logger.debug('Starting cache warmup from CDN...')
      app = Tml::Application.new(key: Tml.config.application[:key], cdn_host: Tml.config.application[:cdn_host])
      extract_version(app, version)

      Tml.logger.debug("Warming Up Version: #{Tml.cache.version}")

      application = app.api_client.get_from_cdn('application', {t: Time.now.to_i})
      Tml.cache.store(Tml::Application.cache_key, application)

      sources = app.api_client.get_from_cdn('sources', {t: Time.now.to_i}, {uncompressed: true})

      application['languages'].each do |lang|
        locale = lang['locale']
        language = app.api_client.get_from_cdn("#{locale}/language", {t: Time.now.to_i})
        Tml.cache.store(Tml::Language.cache_key(locale), language)

        sources.each do |src|
          source = app.api_client.get_from_cdn("#{locale}/sources/#{src}", {t: Time.now.to_i})
          Tml.cache.store(Tml::Source.cache_key(locale, src), source)
        end
      end

      t1 = Time.now
      Tml.logger.debug("Cache warmup took #{t1-t0}s")
    end
Warms up cache from CDN