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

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

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

      archive_name = "#{Tml.cache.version}.tar.gz"
      path = "#{cache_path}/#{archive_name}"
      url = "#{app.cdn_host}/#{Tml.config.application[:key]}/#{archive_name}"

      Tml.logger.debug("Downloading cache file: #{url}")
      open(path, 'wb') do |file|
        file << open(url).read
      end

      Tml.logger.debug('Extracting cache file...')
      version_path = "#{cache_path}/#{Tml.cache.version}"
      Tml::Utils.untar(Tml::Utils.ungzip(File.new(path)), version_path)
      Tml.logger.debug("Cache has been stored in #{version_path}")

      File.unlink(path)

      begin
        current_path = 'current'
        FileUtils.chdir(cache_path)
        FileUtils.rm(current_path) if File.exist?(current_path)
        FileUtils.ln_s(Tml.cache.version.to_s, current_path)
        Tml.logger.debug("The new version #{Tml.cache.version} has been marked as current")
      rescue Exception => ex
        Tml.logger.debug("Could not generate current symlink to the cache path: #{ex.message}")
      end

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

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

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

      archive_name = "#{Tml.cache.version}.tar.gz"
      path = "#{cache_path}/#{archive_name}"
      url = "#{app.cdn_host}/#{Tml.config.application[:key]}/#{archive_name}"

      Tml.logger.debug("Downloading cache file: #{url}")
      open(path, 'wb') do |file|
        file << open(url).read
      end

      Tml.logger.debug('Extracting cache file...')
      version_path = "#{cache_path}/#{Tml.cache.version}"
      Tml::Utils.untar(Tml::Utils.ungzip(File.new(path)), version_path)
      Tml.logger.debug("Cache has been stored in #{version_path}")

      File.unlink(path)

      begin
        current_path = 'current'
        FileUtils.chdir(cache_path)
        FileUtils.rm(current_path) if File.exist?(current_path)
        FileUtils.ln_s(Tml.cache.version.to_s, current_path)
        Tml.logger.debug("The new version #{Tml.cache.version} has been marked as current")
      rescue Exception => ex
        Tml.logger.debug("Could not generate current symlink to the cache path: #{ex.message}")
      end

      t1 = Time.now
      Tml.logger.debug("Cache download took #{t1-t0}s")
    end
downloads cache from the CDN