Module: LaunchDarkly::Interfaces::FeatureStore
- Included in:
- LaunchDarkly::InMemoryFeatureStore, LaunchDarkly::Integrations::Util::CachingStoreWrapper, RedisFeatureStore
- Defined in:
- lib/ldclient-rb/interfaces.rb
Overview
Mixin that defines the required methods of a feature store implementation. The LaunchDarkly client uses the feature store to persist feature flags and related objects received from the LaunchDarkly service. Implementations must support concurrent access and updates. For more about how feature stores can be used, see: Using a persistent feature store.
An entity that can be stored in a feature store is a hash that can be converted to and from
JSON, and that has at a minimum the following properties: :key
, a string that is unique
among entities of the same kind; :version
, an integer that is higher for newer data;
:deleted
, a boolean (optional, defaults to false) that if true means this is a
placeholder for a deleted entity.
To represent the different kinds of objects that can be stored, such as feature flags and
segments, the SDK will provide a "kind" object; this is a hash with a single property,
:namespace
, which is a short string unique to that kind. This string can be used as a
collection name or a key prefix.
The default implementation is LaunchDarkly::InMemoryFeatureStore. Several implementations that use databases can be found in LaunchDarkly::Integrations. If you want to write a new implementation, see LaunchDarkly::Integrations::Util for tools that can make this task simpler.
Instance Method Summary collapse
-
#all(kind) ⇒ Hash
Returns all stored entities of the specified kind, not including deleted entities.
-
#delete(kind, key, version) ⇒ void
Attempt to delete an entity if it exists.
-
#get(kind, key) ⇒ Hash
Returns the entity to which the specified key is mapped, if any.
-
#init(all_data) ⇒ void
Initializes (or re-initializes) the store with the specified set of entities.
-
#initialized? ⇒ Boolean
Checks whether this store has been initialized.
-
#stop ⇒ void
Performs any necessary cleanup to shut down the store when the client is being shut down.
-
#upsert(kind, item) ⇒ void
Attempt to add an entity, or update an existing entity with the same key.
Instance Method Details
#all(kind) ⇒ Hash
Returns all stored entities of the specified kind, not including deleted entities.
67 68 |
# File 'lib/ldclient-rb/interfaces.rb', line 67 def all(kind) end |
#delete(kind, key, version) ⇒ void
This method returns an undefined value.
Attempt to delete an entity if it exists. Deletion should only succeed if the
version
parameter is greater than the existing entity's :version
; otherwise, the
method should do nothing.
92 93 |
# File 'lib/ldclient-rb/interfaces.rb', line 92 def delete(kind, key, version) end |
#get(kind, key) ⇒ Hash
Returns the entity to which the specified key is mapped, if any.
57 58 |
# File 'lib/ldclient-rb/interfaces.rb', line 57 def get(kind, key) end |
#init(all_data) ⇒ void
This method returns an undefined value.
Initializes (or re-initializes) the store with the specified set of entities. Any existing entries will be removed. Implementations can assume that this data set is up to date-- there is no need to perform individual version comparisons between the existing objects and the supplied features.
If possible, the store should update the entire data set atomically. If that is not possible, it should iterate through the outer hash and then the inner hash using the existing iteration order of those hashes (the SDK will ensure that the items were inserted into the hashes in the correct order), storing each item, and then delete any leftover items at the very end.
46 47 |
# File 'lib/ldclient-rb/interfaces.rb', line 46 def init(all_data) end |
#initialized? ⇒ Boolean
Checks whether this store has been initialized. That means that init
has been called
either by this process, or (if the store can be shared) by another process. This
method will be called frequently, so it should be efficient. You can assume that if it
has returned true once, it can continue to return true, i.e. a store cannot become
uninitialized again.
104 105 |
# File 'lib/ldclient-rb/interfaces.rb', line 104 def initialized? end |
#stop ⇒ void
This method returns an undefined value.
Performs any necessary cleanup to shut down the store when the client is being shut down.
112 113 |
# File 'lib/ldclient-rb/interfaces.rb', line 112 def stop end |
#upsert(kind, item) ⇒ void
This method returns an undefined value.
Attempt to add an entity, or update an existing entity with the same key. An update
should only succeed if the new item's :version
is greater than the old one;
otherwise, the method should do nothing.
79 80 |
# File 'lib/ldclient-rb/interfaces.rb', line 79 def upsert(kind, item) end |