class Yoda::Store::RegistryCache

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

Attributes

data[R]

@return [Concurrent::Map]

Public Class Methods

new() click to toggle source
# File lib/yoda/store/registry_cache.rb, line 8
def initialize
  @data = Concurrent::Map.new
end

Public Instance Methods

clear_from_patch(patch) click to toggle source

@param patch [Objects::Patch]

# File lib/yoda/store/registry_cache.rb, line 30
def clear_from_patch(patch)
  patch.keys.each { |key| delete(key) }
end
delete(key) click to toggle source

@param key [String, Symbol]

# File lib/yoda/store/registry_cache.rb, line 21
def delete(key)
  data.delete(key.to_sym)
end
delete_all() click to toggle source
# File lib/yoda/store/registry_cache.rb, line 25
def delete_all
  data.clear
end
fetch_or_calc(key) { || ... } click to toggle source

@param key [String, Symbol]

# 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