Class: LaunchDarkly::InMemoryFeatureStore
- Inherits:
-
Object
- Object
- LaunchDarkly::InMemoryFeatureStore
- Includes:
- LaunchDarkly::Interfaces::FeatureStore
- Defined in:
- lib/ldclient-rb/in_memory_store.rb
Overview
Default implementation of the LaunchDarkly client’s feature store, using an in-memory cache. This object holds feature flags and related data received from LaunchDarkly. Database-backed implementations are available in Integrations.
Instance Method Summary collapse
- #all(kind) ⇒ Object
- #delete(kind, key, version) ⇒ Object
- #get(kind, key) ⇒ Object
- #init(all_data) ⇒ Object
-
#initialize ⇒ InMemoryFeatureStore
constructor
A new instance of InMemoryFeatureStore.
- #initialized? ⇒ Boolean
- #monitoring_enabled? ⇒ Boolean
- #stop ⇒ Object
- #upsert(kind, item) ⇒ Object
Constructor Details
#initialize ⇒ InMemoryFeatureStore
Returns a new instance of InMemoryFeatureStore.
37 38 39 40 41 |
# File 'lib/ldclient-rb/in_memory_store.rb', line 37 def initialize @items = Hash.new @lock = Concurrent::ReadWriteLock.new @initialized = Concurrent::AtomicBoolean.new(false) end |
Instance Method Details
#all(kind) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/ldclient-rb/in_memory_store.rb', line 55 def all(kind) @lock.with_read_lock do coll = @items[kind] (coll.nil? ? Hash.new : coll).select { |_k, f| not f[:deleted] } end end |
#delete(kind, key, version) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ldclient-rb/in_memory_store.rb', line 62 def delete(kind, key, version) @lock.with_write_lock do coll = @items[kind] if coll.nil? coll = Hash.new @items[kind] = coll end old = coll[key.to_sym] if old.nil? || old[:version] < version coll[key.to_sym] = { deleted: true, version: version } end end end |
#get(kind, key) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/ldclient-rb/in_memory_store.rb', line 47 def get(kind, key) @lock.with_read_lock do coll = @items[kind] f = coll.nil? ? nil : coll[key.to_sym] (f.nil? || f[:deleted]) ? nil : f end end |
#init(all_data) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/ldclient-rb/in_memory_store.rb', line 77 def init(all_data) @lock.with_write_lock do @items.replace(all_data) @initialized.make_true end end |
#initialized? ⇒ Boolean
99 100 101 |
# File 'lib/ldclient-rb/in_memory_store.rb', line 99 def initialized? @initialized.value end |
#monitoring_enabled? ⇒ Boolean
43 44 45 |
# File 'lib/ldclient-rb/in_memory_store.rb', line 43 def monitoring_enabled? false end |
#stop ⇒ Object
103 104 105 |
# File 'lib/ldclient-rb/in_memory_store.rb', line 103 def stop # nothing to do end |
#upsert(kind, item) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ldclient-rb/in_memory_store.rb', line 84 def upsert(kind, item) @lock.with_write_lock do coll = @items[kind] if coll.nil? coll = Hash.new @items[kind] = coll end old = coll[item[:key].to_sym] if old.nil? || old[:version] < item[:version] coll[item[:key].to_sym] = item end end end |