Class: Gemstash::Cache

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gemstash/cache.rb

Overview

Cache object which knows about what things are cached and what keys to use for them. Under the hood is either a Memcached client via the dalli gem, or an in memory client via the lru_redux gem.

Constant Summary collapse

EXPIRY =
30 * 60

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Cache

Returns a new instance of Cache.



13
14
15
# File 'lib/gemstash/cache.rb', line 13

def initialize(client)
  @client = client
end

Instance Method Details

#authorization(auth_key) ⇒ Object



17
18
19
# File 'lib/gemstash/cache.rb', line 17

def authorization(auth_key)
  @client.get("auths/#{auth_key}")
end

#dependencies(scope, gems) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/gemstash/cache.rb', line 29

def dependencies(scope, gems)
  key_prefix = "deps/v1/#{scope}/"
  keys = gems.map {|g| "#{key_prefix}#{g}" }

  @client.get_multi(keys) do |key, value|
    yield(key.sub(key_prefix, ""), value)
  end
end

#invalidate_authorization(auth_key) ⇒ Object



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

def invalidate_authorization(auth_key)
  @client.delete("auths/#{auth_key}")
end

#invalidate_gem(scope, gem) ⇒ Object



42
43
44
45
# File 'lib/gemstash/cache.rb', line 42

def invalidate_gem(scope, gem)
  @client.delete("deps/v1/#{scope}/#{gem}")
  Gemstash::SpecsBuilder.invalidate_stored if scope == "private"
end

#set_authorization(auth_key, value) ⇒ Object



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

def set_authorization(auth_key, value)
  @client.set("auths/#{auth_key}", value, EXPIRY)
end

#set_dependency(scope, gem, value) ⇒ Object



38
39
40
# File 'lib/gemstash/cache.rb', line 38

def set_dependency(scope, gem, value)
  @client.set("deps/v1/#{scope}/#{gem}", value, EXPIRY)
end