Class: Yoda::Store::Registry::Cache
- Inherits:
-
Object
- Object
- Yoda::Store::Registry::Cache
- 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
- #clear_from_patch(patch) ⇒ Object
- #delete(key) ⇒ Object
- #delete_all ⇒ Object
- #fetch_or_calc(key) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize ⇒ Cache
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
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
46 47 48 |
# File 'lib/yoda/store/registry/cache.rb', line 46 def delete(key) data.delete(key.to_sym) end |
#delete_all ⇒ Object
50 51 52 |
# File 'lib/yoda/store/registry/cache.rb', line 50 def delete_all data.clear end |
#fetch_or_calc(key) ⇒ Object
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 |