Class: Bundler::CompactIndexClient::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/compact_index_client/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory, fetcher = nil) ⇒ Cache

Returns a new instance of Cache.



10
11
12
13
14
15
16
17
18
19
# File 'lib/bundler/compact_index_client/cache.rb', line 10

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

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



8
9
10
# File 'lib/bundler/compact_index_client/cache.rb', line 8

def directory
  @directory
end

Instance Method Details

#info(name, remote_checksum = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/bundler/compact_index_client/cache.rb', line 29

def info(name, remote_checksum = nil)
  path = info_path(name)

  if remote_checksum && remote_checksum != SharedHelpers.checksum_for_file(path, :MD5)
    fetch("info/#{name}", path, info_etag_path(name))
  else
    Bundler::CompactIndexClient.debug { "update skipped info/#{name} (#{remote_checksum ? "versions index checksum is nil" : "versions index checksum matches local"})" }
    read(path)
  end
end

#namesObject



21
22
23
# File 'lib/bundler/compact_index_client/cache.rb', line 21

def names
  fetch("names", names_path, names_etag_path)
end

#reset!Object



40
41
42
# File 'lib/bundler/compact_index_client/cache.rb', line 40

def reset!
  @mutex.synchronize { @endpoints.clear }
end

#versionsObject



25
26
27
# File 'lib/bundler/compact_index_client/cache.rb', line 25

def versions
  fetch("versions", versions_path, versions_etag_path)
end