Class PersistentDataStoreBuilder
- All Implemented Interfaces:
DataStoreFactory
public abstract class PersistentDataStoreBuilder extends java.lang.Object implements DataStoreFactory
Several database integrations exist for the LaunchDarkly SDK, each with its own behavior and options
specific to that database; this is described via some implementation of PersistentDataStoreFactory.
There is also universal behavior that the SDK provides for all persistent data stores, such as caching;
the PersistentDataStoreBuilder adds this.
After configuring this object, pass it to LDConfig.Builder.dataStore(DataStoreFactory)
to use it in the SDK configuration. For example, using the Redis integration:
LDConfig config = new LDConfig.Builder()
.dataStore(
Components.persistentDataStore(
Redis.dataStore().url("redis://my-redis-host")
).cacheSeconds(15)
)
.build();
In this example, .url() is an option specifically for the Redis integration, whereas
cacheSeconds() is an option that can be used for any persistent data store.
Note that this class is abstract; the actual implementation is created by calling
Components.persistentDataStore(PersistentDataStoreFactory).
- Since:
- 4.12.0
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPersistentDataStoreBuilder.StaleValuesPolicyPossible values forstaleValuesPolicy(StaleValuesPolicy). -
Field Summary
Fields Modifier and Type Field Description protected java.time.DurationcacheTimestatic java.time.DurationDEFAULT_CACHE_TTLThe default value for the cache TTL.protected PersistentDataStoreFactorypersistentDataStoreFactoryprotected booleanrecordCacheStatsprotected PersistentDataStoreBuilder.StaleValuesPolicystaleValuesPolicy -
Constructor Summary
Constructors Modifier Constructor Description protectedPersistentDataStoreBuilder(PersistentDataStoreFactory persistentDataStoreFactory)Creates a new builder. -
Method Summary
Modifier and Type Method Description PersistentDataStoreBuildercacheForever()Specifies that the in-memory cache should never expire.PersistentDataStoreBuildercacheMillis(long millis)Shortcut for callingcacheTime(Duration)with a duration in milliseconds.PersistentDataStoreBuildercacheSeconds(long seconds)Shortcut for callingcacheTime(Duration)with a duration in seconds.PersistentDataStoreBuildercacheTime(java.time.Duration cacheTime)Specifies the cache TTL.PersistentDataStoreBuildernoCaching()Specifies that the SDK should not use an in-memory cache for the persistent data store.PersistentDataStoreBuilderrecordCacheStats(boolean recordCacheStats)Enables monitoring of the in-memory cache.PersistentDataStoreBuilderstaleValuesPolicy(PersistentDataStoreBuilder.StaleValuesPolicy staleValuesPolicy)Specifies how the cache (if any) should deal with old values when the cache TTL expires.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.launchdarkly.sdk.server.interfaces.DataStoreFactory
createDataStore
-
Field Details
-
DEFAULT_CACHE_TTL
public static final java.time.Duration DEFAULT_CACHE_TTLThe default value for the cache TTL. -
persistentDataStoreFactory
-
cacheTime
protected java.time.Duration cacheTime -
staleValuesPolicy
-
recordCacheStats
protected boolean recordCacheStats
-
-
Constructor Details
-
PersistentDataStoreBuilder
Creates a new builder.- Parameters:
persistentDataStoreFactory- the factory implementation for the specific data store type
-
-
Method Details
-
noCaching
Specifies that the SDK should not use an in-memory cache for the persistent data store. This means that every feature flag evaluation will trigger a data store query.- Returns:
- the builder
-
cacheTime
Specifies the cache TTL. Items will be evicted or refreshed (depending on the StaleValuesPolicy) after this amount of time from the time when they were originally cached.If the value is zero, caching is disabled (equivalent to
noCaching()).If the value is negative, data is cached forever (equivalent to
cacheForever()).- Parameters:
cacheTime- the cache TTL; null to use the default- Returns:
- the builder
-
cacheMillis
Shortcut for callingcacheTime(Duration)with a duration in milliseconds.- Parameters:
millis- the cache TTL in milliseconds- Returns:
- the builder
-
cacheSeconds
Shortcut for callingcacheTime(Duration)with a duration in seconds.- Parameters:
seconds- the cache TTL in seconds- Returns:
- the builder
-
cacheForever
Specifies that the in-memory cache should never expire. In this mode, data will be written to both the underlying persistent store and the cache, but will only ever be read from the persistent store if the SDK is restarted.Use this mode with caution: it means that in a scenario where multiple processes are sharing the database, and the current process loses connectivity to LaunchDarkly while other processes are still receiving updates and writing them to the database, the current process will have stale data.
- Returns:
- the builder
-
staleValuesPolicy
public PersistentDataStoreBuilder staleValuesPolicy(PersistentDataStoreBuilder.StaleValuesPolicy staleValuesPolicy)Specifies how the cache (if any) should deal with old values when the cache TTL expires. The default isPersistentDataStoreBuilder.StaleValuesPolicy.EVICT. This property has no effect if caching is disabled.- Parameters:
staleValuesPolicy- aPersistentDataStoreBuilder.StaleValuesPolicyconstant- Returns:
- the builder
-
recordCacheStats
Enables monitoring of the in-memory cache.If set to true, this makes caching statistics available through the
By default, it is false: statistics will not be recorded and theDataStoreStatusProviderthat you can obtain from the client instance. This may slightly decrease performance, due to the need to record statistics for each cache operation.DataStoreStatusProvider.getCacheStats()method will return null.- Parameters:
recordCacheStats- true to record caching statiistics- Returns:
- the builder
- Since:
- 5.0.0
-