Class: SettingsReader::VaultResolver::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/settings_reader/vault_resolver/cache.rb

Overview

Secrets cache for seamless dynamic keys and renewal operations

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



5
6
7
# File 'lib/settings_reader/vault_resolver/cache.rb', line 5

def initialize
  @secrets = {}
end

Instance Method Details

#active_entries(&block) ⇒ Object



39
40
41
# File 'lib/settings_reader/vault_resolver/cache.rb', line 39

def active_entries(&block)
  @secrets.values.select(&:active?).each(&block)
end

#clear(entry) ⇒ Object



20
21
22
23
# File 'lib/settings_reader/vault_resolver/cache.rb', line 20

def clear(entry)
  @secrets.delete(cache_key(entry.address))
  nil
end

#clear_allObject



43
44
45
# File 'lib/settings_reader/vault_resolver/cache.rb', line 43

def clear_all
  @secrets = {}
end

#entries(&block) ⇒ Object



35
36
37
# File 'lib/settings_reader/vault_resolver/cache.rb', line 35

def entries(&block)
  @secrets.each_value(&block)
end

#fetch(address, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/settings_reader/vault_resolver/cache.rb', line 25

def fetch(address, &block)
  if !address.no_cache? && (existing_entry = retrieve(address))
    existing_entry
  else
    new_entry = block.call(address)
    save(new_entry) if new_entry
    new_entry
  end
end

#retrieve(address) ⇒ Object



9
10
11
12
13
14
# File 'lib/settings_reader/vault_resolver/cache.rb', line 9

def retrieve(address)
  return nil unless (entry = @secrets[cache_key(address)])
  return clear(entry) if entry.expired?

  entry
end

#save(entry) ⇒ Object



16
17
18
# File 'lib/settings_reader/vault_resolver/cache.rb', line 16

def save(entry)
  @secrets[cache_key(entry.address)] = entry
end