Class: EppoClient::ConfigurationStore
- Inherits:
-
Object
- Object
- EppoClient::ConfigurationStore
- Defined in:
- lib/configuration_store.rb
Overview
A thread safe store for the configurations to ensure that retrievals pull from a single source of truth
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#lock ⇒ Object
readonly
Returns the value of attribute lock.
Instance Method Summary collapse
- #assign_configurations(configs) ⇒ Object
-
#initialize(max_size) ⇒ ConfigurationStore
constructor
A new instance of ConfigurationStore.
- #retrieve_configuration(key) ⇒ Object
Constructor Details
#initialize(max_size) ⇒ ConfigurationStore
Returns a new instance of ConfigurationStore.
12 13 14 15 |
# File 'lib/configuration_store.rb', line 12 def initialize(max_size) @cache = EppoClient::LRUCache.new(max_size) @lock = Concurrent::ReadWriteLock.new end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
10 11 12 |
# File 'lib/configuration_store.rb', line 10 def cache @cache end |
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
10 11 12 |
# File 'lib/configuration_store.rb', line 10 def lock @lock end |
Instance Method Details
#assign_configurations(configs) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/configuration_store.rb', line 21 def assign_configurations(configs) @lock.with_write_lock do configs.each do |key, config| @cache[key] = config end end end |
#retrieve_configuration(key) ⇒ Object
17 18 19 |
# File 'lib/configuration_store.rb', line 17 def retrieve_configuration(key) @lock.with_read_lock { @cache[key] } end |