Class: Gemkeeper::CompactIndexServer::GemCache

Inherits:
Object
  • Object
show all
Defined in:
lib/gemkeeper/compact_index_server/gem_cache.rb

Overview

Per-gem caching of /info documents and .gem binaries from RubyGems.org. Serves from the local RubyGems cache, then the disk cache, then upstream.

Constant Summary collapse

INFO_TTL =

60 minutes

3600

Instance Method Summary collapse

Constructor Details

#initialize(store, client) ⇒ GemCache

Returns a new instance of GemCache.



13
14
15
16
# File 'lib/gemkeeper/compact_index_server/gem_cache.rb', line 13

def initialize(store, client)
  @store  = store
  @client = client
end

Instance Method Details

#binary(filename) ⇒ Object

Returns a local path to the gem binary, or nil (not found). Raises UpstreamUnavailableError when unreachable with no cached copy.



34
35
36
37
38
# File 'lib/gemkeeper/compact_index_server/gem_cache.rb', line 34

def binary(filename)
  system_gem_path(filename) ||
    disk_cache_path(filename) ||
    fetch_binary(filename, @store.path("gems/#{filename}"))
end

#info(gemname) ⇒ Object

Returns etag: or nil (not found). Raises UpstreamUnavailableError when unreachable with no cache.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gemkeeper/compact_index_server/gem_cache.rb', line 20

def info(gemname)
  path = @store.path("info/#{gemname}")
  meta = @store.read_meta("info/#{gemname}")
  return cached_entry(path, meta) if fresh?(path, meta)

  fetch_info(gemname, path, meta)
rescue UpstreamUnavailableError
  raise unless File.exist?(path)

  cached_entry(path, meta)
end