Class: LaunchDarkly::Impl::DataStore::InMemoryFeatureStoreV2 Private

Inherits:
Object
  • Object
show all
Includes:
LaunchDarkly::Interfaces::DataSystem::ReadOnlyStore
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.

Since:

  • 5.5.0

Instance Method Summary collapse

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.

Since:

  • 5.5.0



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.

Parameters:

Returns:

  • (Hash)

    Hash of keys to items (excluding deleted items)

Since:

  • 5.5.0



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.

Parameters:

Returns:

  • (Boolean)

    true if successful, false otherwise

Since:

  • 5.5.0



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.message}" }
  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.

Parameters:

Returns:

  • (Hash, nil)

    The item, or nil if not found or deleted

Since:

  • 5.5.0



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.

Returns:

  • (Boolean)

Since:

  • 5.5.0



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.

Parameters:

Returns:

  • (Boolean)

    true if successful, false otherwise

Since:

  • 5.5.0



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.message}" }
  false
end