Class PersistentDataStoreBuilder
- java.lang.Object
-
- com.launchdarkly.sdk.server.integrations.PersistentDataStoreBuilder
-
- All Implemented Interfaces:
ComponentConfigurer<DataStore>
public abstract class PersistentDataStoreBuilder extends java.lang.Object implements ComponentConfigurer<DataStore>
A configurable factory for a persistent data store.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
PersistentDataStore
. There is also universal behavior that the SDK provides for all persistent data stores, such as caching; thePersistentDataStoreBuilder
adds this.After configuring this object, pass it to
LDConfig.Builder.dataStore(ComponentConfigurer)
to use it in the SDK configuration. For example, using the Redis integration:
In this example,LDConfig config = new LDConfig.Builder() .dataStore( Components.persistentDataStore( Redis.dataStore().url("redis://my-redis-host") ).cacheSeconds(15) ) .build();
.url()
is an option specifically for the Redis integration, whereascacheSeconds()
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(ComponentConfigurer)
.- Since:
- 4.12.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PersistentDataStoreBuilder.StaleValuesPolicy
Possible values forstaleValuesPolicy(StaleValuesPolicy)
.
-
Field Summary
Fields Modifier and Type Field Description protected java.time.Duration
cacheTime
static java.time.Duration
DEFAULT_CACHE_TTL
The default value for the cache TTL.protected ComponentConfigurer<PersistentDataStore>
persistentDataStoreConfigurer
protected boolean
recordCacheStats
protected PersistentDataStoreBuilder.StaleValuesPolicy
staleValuesPolicy
-
Constructor Summary
Constructors Modifier Constructor Description protected
PersistentDataStoreBuilder(ComponentConfigurer<PersistentDataStore> persistentDataStoreConfigurer)
Creates a new builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PersistentDataStoreBuilder
cacheForever()
Specifies that the in-memory cache should never expire.PersistentDataStoreBuilder
cacheMillis(long millis)
Shortcut for callingcacheTime(Duration)
with a duration in milliseconds.PersistentDataStoreBuilder
cacheSeconds(long seconds)
Shortcut for callingcacheTime(Duration)
with a duration in seconds.PersistentDataStoreBuilder
cacheTime(java.time.Duration cacheTime)
Specifies the cache TTL.PersistentDataStoreBuilder
noCaching()
Specifies that the SDK should not use an in-memory cache for the persistent data store.PersistentDataStoreBuilder
recordCacheStats(boolean recordCacheStats)
Enables monitoring of the in-memory cache.PersistentDataStoreBuilder
staleValuesPolicy(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, wait
-
Methods inherited from interface com.launchdarkly.sdk.server.subsystems.ComponentConfigurer
build
-
-
-
-
Field Detail
-
DEFAULT_CACHE_TTL
public static final java.time.Duration DEFAULT_CACHE_TTL
The default value for the cache TTL.
-
persistentDataStoreConfigurer
protected final ComponentConfigurer<PersistentDataStore> persistentDataStoreConfigurer
-
cacheTime
protected java.time.Duration cacheTime
-
staleValuesPolicy
protected PersistentDataStoreBuilder.StaleValuesPolicy staleValuesPolicy
-
recordCacheStats
protected boolean recordCacheStats
-
-
Constructor Detail
-
PersistentDataStoreBuilder
protected PersistentDataStoreBuilder(ComponentConfigurer<PersistentDataStore> persistentDataStoreConfigurer)
Creates a new builder.- Parameters:
persistentDataStoreConfigurer
- the factory implementation for the specific data store type
-
-
Method Detail
-
noCaching
public PersistentDataStoreBuilder 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
public PersistentDataStoreBuilder cacheTime(java.time.Duration 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
public PersistentDataStoreBuilder cacheMillis(long millis)
Shortcut for callingcacheTime(Duration)
with a duration in milliseconds.- Parameters:
millis
- the cache TTL in milliseconds- Returns:
- the builder
-
cacheSeconds
public PersistentDataStoreBuilder cacheSeconds(long seconds)
Shortcut for callingcacheTime(Duration)
with a duration in seconds.- Parameters:
seconds
- the cache TTL in seconds- Returns:
- the builder
-
cacheForever
public PersistentDataStoreBuilder 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.StaleValuesPolicy
constant- Returns:
- the builder
-
recordCacheStats
public PersistentDataStoreBuilder recordCacheStats(boolean 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 theDataStoreStatusProvider
that 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
-
-