Class: Yoda::Store::Registry::Cache

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

Overview

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

Defined Under Namespace

Classes: RegistryWrapper

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



33
34
35
# File 'lib/yoda/store/registry/cache.rb', line 33

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

Instance Method Details

#clear_from_patch(patch) ⇒ Object

Parameters:



55
56
57
# File 'lib/yoda/store/registry/cache.rb', line 55

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

#delete(key) ⇒ Object

Parameters:

  • key (String, Symbol)


46
47
48
# File 'lib/yoda/store/registry/cache.rb', line 46

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

#delete_allObject



50
51
52
# File 'lib/yoda/store/registry/cache.rb', line 50

def delete_all
  data.clear
end

#fetch_or_calc(key) ⇒ Object

Parameters:

  • key (String, Symbol)


38
39
40
41
42
43
# File 'lib/yoda/store/registry/cache.rb', line 38

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