Class: Yoda::Store::RegistryCache

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/store/registry_cache.rb

Overview

Registry Cache is a cache layer for Registry. This class intended to reduce patch calculations of PatchSet#patch.

Instance Method Summary collapse

Constructor Details

#initializeRegistryCache

Returns a new instance of RegistryCache.



8
9
10
# File 'lib/yoda/store/registry_cache.rb', line 8

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

Instance Method Details

#clear_from_patch(patch) ⇒ Object

Parameters:



30
31
32
# File 'lib/yoda/store/registry_cache.rb', line 30

def clear_from_patch(patch)
  patch.keys.each { |key| delete(key) }
end

#delete(key) ⇒ Object

Parameters:

  • key (String, Symbol)


21
22
23
# File 'lib/yoda/store/registry_cache.rb', line 21

def delete(key)
  data.delete(key.to_sym)
end

#delete_allObject



25
26
27
# File 'lib/yoda/store/registry_cache.rb', line 25

def delete_all
  data.clear
end

#fetch_or_calc(key) ⇒ Object

Parameters:

  • key (String, Symbol)


13
14
15
16
17
18
# File 'lib/yoda/store/registry_cache.rb', line 13

def fetch_or_calc(key)
  if cache = data.get(key.to_sym)
    return cache
  end
  yield.tap { |value| data.put_if_absent(key.to_sym, value) }
end