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 =
Env.current.config[:cache_expiration]

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Cache

Returns a new instance of Cache.



15
16
17
# File 'lib/gemstash/cache.rb', line 15

def initialize(client)
  @client = client
end

Instance Method Details

#authorization(auth_key) ⇒ Object



19
20
21
# File 'lib/gemstash/cache.rb', line 19

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

#dependencies(scope, gems) ⇒ Object



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

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



27
28
29
# File 'lib/gemstash/cache.rb', line 27

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

#invalidate_gem(scope, gem) ⇒ Object



44
45
46
47
# File 'lib/gemstash/cache.rb', line 44

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



23
24
25
# File 'lib/gemstash/cache.rb', line 23

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

#set_dependency(scope, gem, value) ⇒ Object



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

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