Class: LaunchDarkly::Impl::DataStore::InMemoryFeatureStoreV2 Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::DataStore::InMemoryFeatureStoreV2
- Defined in:
- lib/ldclient-rb/impl/data_store/in_memory_feature_store.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
InMemoryFeatureStoreV2 is a read-only in-memory store implementation for FDv2.
Instance Method Summary collapse
-
#all(kind) ⇒ Hash
private
Retrieves all items of a given kind.
-
#apply_delta(collections) ⇒ Boolean
private
Applies a delta update to the store.
-
#get(kind, key) ⇒ Hash?
private
Retrieves an item by kind and key.
-
#initialize(logger) ⇒ InMemoryFeatureStoreV2
constructor
private
A new instance of InMemoryFeatureStoreV2.
-
#initialized? ⇒ Boolean
private
Returns whether the store has been initialized.
-
#set_basis(collections) ⇒ Boolean
private
Initializes the store with a full set of data, replacing any existing data.
Constructor Details
#initialize(logger) ⇒ InMemoryFeatureStoreV2
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of InMemoryFeatureStoreV2.
16 17 18 19 20 21 |
# File 'lib/ldclient-rb/impl/data_store/in_memory_feature_store.rb', line 16 def initialize(logger) @logger = logger @lock = Concurrent::ReadWriteLock.new @initialized = Concurrent::AtomicBoolean.new(false) @items = {} end |
Instance Method Details
#all(kind) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Retrieves all items of a given kind.
42 43 44 45 46 47 48 49 |
# File 'lib/ldclient-rb/impl/data_store/in_memory_feature_store.rb', line 42 def all(kind) @lock.with_read_lock do items_of_kind = @items[kind] return {} if items_of_kind.nil? items_of_kind.select { |_k, item| !item[:deleted] } end end |
#apply_delta(collections) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Applies a delta update to the store.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ldclient-rb/impl/data_store/in_memory_feature_store.rb', line 86 def apply_delta(collections) all_decoded = decode_collection(collections) return false if all_decoded.nil? @lock.with_write_lock do all_decoded.each do |kind, kind_data| items_of_kind = @items[kind] ||= {} kind_data.each do |key, item| items_of_kind[key] = item end end end true rescue => e @logger.error { "[LDClient] Failed applying apply_delta: #{e.}" } false end |
#get(kind, key) ⇒ Hash?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Retrieves an item by kind and key.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ldclient-rb/impl/data_store/in_memory_feature_store.rb', line 26 def get(kind, key) @lock.with_read_lock do items_of_kind = @items[kind] return nil if items_of_kind.nil? item = items_of_kind[key] return nil if item.nil? return nil if item[:deleted] item end end |
#initialized? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether the store has been initialized.
54 55 56 |
# File 'lib/ldclient-rb/impl/data_store/in_memory_feature_store.rb', line 54 def initialized? @initialized.value end |
#set_basis(collections) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the store with a full set of data, replacing any existing data.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ldclient-rb/impl/data_store/in_memory_feature_store.rb', line 64 def set_basis(collections) all_decoded = decode_collection(collections) return false if all_decoded.nil? @lock.with_write_lock do @items.clear @items.update(all_decoded) @initialized.make_true end true rescue => e @logger.error { "[LDClient] Failed applying set_basis: #{e.}" } false end |