class Gem::CompactIndexClient::Cache

Calls the Updater to update the cached files on disk, reads the cached files and returns their contents.

Attributes

Public Class Methods

# File lib/rubygems/compact_index_client/cache.rb, line 14
def initialize(directory, fetcher = nil)
  @directory = Pathname.new(directory).expand_path
  @updater = Updater.new(fetcher) if fetcher
  @mutex = Thread::Mutex.new
  @endpoints = Set.new

  @info_root = mkdir("info")
  @special_characters_info_root = mkdir("info-special-characters")
  @info_etag_root = mkdir("info-etags")
end

Public Instance Methods

Fetch a single gem’s info file without consulting the versions index, refreshing the cached file with a conditional request.

# File lib/rubygems/compact_index_client/cache.rb, line 46
def fetch_info(name)
  fetch("info/#{name}", info_path(name), info_etag_path(name))
end
# File lib/rubygems/compact_index_client/cache.rb, line 33
def info(name, remote_checksum = nil)
  path = info_path(name)

  if remote_checksum && remote_checksum != checksum_for_file(path)
    fetch("info/#{name}", path, info_etag_path(name))
  else
    Gem::CompactIndexClient.debug { "update skipped info/#{name} (#{remote_checksum ? "versions index checksum matches local" : "versions index checksum is nil"})" }
    read(path)
  end
end
# File lib/rubygems/compact_index_client/cache.rb, line 25
def names
  fetch("names", names_path, names_etag_path)
end
# File lib/rubygems/compact_index_client/cache.rb, line 50
def reset!
  @mutex.synchronize { @endpoints.clear }
end
# File lib/rubygems/compact_index_client/cache.rb, line 29
def versions
  fetch("versions", versions_path, versions_etag_path)
end