Class: Yoda::Store::RegistryCache
- Inherits:
-
Object
- Object
- Yoda::Store::RegistryCache
- 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
- #clear_from_patch(patch) ⇒ Object
- #delete(key) ⇒ Object
- #delete_all ⇒ Object
- #fetch_or_calc(key) ⇒ Object
-
#initialize ⇒ RegistryCache
constructor
A new instance of RegistryCache.
Constructor Details
#initialize ⇒ RegistryCache
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
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
21 22 23 |
# File 'lib/yoda/store/registry_cache.rb', line 21 def delete(key) data.delete(key.to_sym) end |
#delete_all ⇒ Object
25 26 27 |
# File 'lib/yoda/store/registry_cache.rb', line 25 def delete_all data.clear end |
#fetch_or_calc(key) ⇒ Object
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 |