Class: EppoClient::ConfigurationStore

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#cacheObject (readonly)

Returns the value of attribute cache.



10
11
12
# File 'lib/configuration_store.rb', line 10

def cache
  @cache
end

#lockObject (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