InMemoryFeatureStore

class InMemoryFeatureStore(initialFeatures: Map<String, Feature> = emptyMap()) : AbstractFeatureStore(source)

In-memory implementation of AbstractFeatureStore that stores features in memory.

This implementation provides thread-safe operations using a Mutex to protect concurrent access. All data is stored in memory and will be lost when the application stops.

Thread Safety: All operations are protected by a reentrant mutex mechanism to ensure thread safety. Internal suspend methods can be safely called from within locked blocks.

Use Cases:

  • Testing and development

  • Simple applications where persistence is not required

  • Prototyping feature flag systems

Parameters

initialFeatures

Optional map of features to initialize the store with

Constructors

Link copied to clipboard
constructor(initialFeatures: Map<String, Feature> = emptyMap())
constructor(config: FF4kConfiguration)

Functions

Link copied to clipboard
open suspend override fun addToGroup(featureId: String, groupName: String)

Add a feature to a group.

Link copied to clipboard
open suspend override fun clear()

Clear all features from the store.

Link copied to clipboard
open suspend operator override fun contains(featureId: String): Boolean

Check if a feature exists in the store.

Link copied to clipboard
open suspend override fun containsGroup(groupName: String): Boolean

Check if a group exists in the store.

Link copied to clipboard
open suspend override fun count(): Int

Get the total number of features in the store.

Link copied to clipboard
open suspend override fun createOrUpdate(feature: Feature)

Create or update a feature (upsert operation).

Link copied to clipboard
open suspend override fun disable(featureId: String)

Disable a feature.

Link copied to clipboard
open suspend override fun disableGroup(groupName: String)

Disable all features associated with the specified group.

Link copied to clipboard
open suspend override fun enable(featureId: String)

Enable a feature.

Link copied to clipboard
open suspend override fun enableGroup(groupName: String)

Enable all features associated with the specified group.

Link copied to clipboard
open suspend operator override fun get(featureId: String): Feature?

Read a feature from the store.

Link copied to clipboard
open suspend override fun getAll(): Map<String, Feature>

Read all features from the store.

Link copied to clipboard
open suspend override fun getAllGroups(): Set<String>

Get all group names in the store.

Link copied to clipboard
open suspend override fun getGroup(groupName: String): Map<String, Feature>

Read all features in a group.

Link copied to clipboard
open suspend override fun getOrThrow(featureId: String): Feature

Read a feature from the store or throw an exception if not found.

Link copied to clipboard
open suspend override fun grantRoleToFeature(featureId: String, roleName: String)

Grant a role/permission to a feature.

Link copied to clipboard
open suspend override fun isEmpty(): Boolean

Check if the store contains no features.

Link copied to clipboard
open suspend operator override fun minusAssign(featureId: String)

Delete a feature from the store.

Link copied to clipboard
open suspend operator override fun plusAssign(feature: Feature)

Create a new feature in the store.

Link copied to clipboard
open suspend override fun removeFromGroup(featureId: String, groupName: String)

Remove a feature from its group.

Link copied to clipboard
open suspend override fun revokeRoleFromFeature(featureId: String, roleName: String)

Revoke a role/permission from a feature.

Link copied to clipboard
open suspend override fun toggle(featureId: String)

Toggle a feature's enabled state.

Link copied to clipboard
open suspend override fun update(feature: Feature)

Update an existing feature in the store.

Link copied to clipboard
open suspend override fun updateFeature(featureId: String, transform: (Feature) -> Feature)

Update a feature using a transformation function.