Class: SecretsManager::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/secrets-manager.rb

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



16
17
18
# File 'lib/secrets-manager.rb', line 16

def initialize
  @_cache = Concurrent::Map.new
end

Instance Method Details

#find(path) ⇒ Object



29
30
31
32
33
34
# File 'lib/secrets-manager.rb', line 29

def find(path)
  fetched = @_cache[path]
  return unless fetched
  return unless !fetched[:expires_at].nil? && (fetched[:expires_at]) > Time.now
  fetched[:value]
end

#resetObject



20
21
22
# File 'lib/secrets-manager.rb', line 20

def reset
  @_cache = Concurrent::Map.new
end

#set(path, value, ttl = 86400) ⇒ Object



24
25
26
27
# File 'lib/secrets-manager.rb', line 24

def set(path, value, ttl = 86400)
  @_cache[path] = {expires_at: (Time.now + ttl), value: value}
  return self
end