public abstract class PersistentDataStoreBuilder extends java.lang.Object implements ComponentConfigurer<DataStore>
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;
the PersistentDataStoreBuilder
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:
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(ComponentConfigurer)
.
Modifier and Type | Class and Description |
---|---|
static class |
PersistentDataStoreBuilder.StaleValuesPolicy
Possible values for
staleValuesPolicy(StaleValuesPolicy) . |
Modifier and Type | Field and 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 |
Modifier | Constructor and Description |
---|---|
protected |
PersistentDataStoreBuilder(ComponentConfigurer<PersistentDataStore> persistentDataStoreConfigurer)
Creates a new builder.
|
Modifier and Type | Method and Description |
---|---|
PersistentDataStoreBuilder |
cacheForever()
Specifies that the in-memory cache should never expire.
|
PersistentDataStoreBuilder |
cacheMillis(long millis)
Shortcut for calling
cacheTime(Duration) with a duration in milliseconds. |
PersistentDataStoreBuilder |
cacheSeconds(long seconds)
Shortcut for calling
cacheTime(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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
build
public static final java.time.Duration DEFAULT_CACHE_TTL
protected final ComponentConfigurer<PersistentDataStore> persistentDataStoreConfigurer
protected java.time.Duration cacheTime
protected PersistentDataStoreBuilder.StaleValuesPolicy staleValuesPolicy
protected boolean recordCacheStats
protected PersistentDataStoreBuilder(ComponentConfigurer<PersistentDataStore> persistentDataStoreConfigurer)
persistentDataStoreConfigurer
- the factory implementation for the specific data store typepublic PersistentDataStoreBuilder noCaching()
public PersistentDataStoreBuilder cacheTime(java.time.Duration cacheTime)
If the value is zero, caching is disabled (equivalent to noCaching()
).
If the value is negative, data is cached forever (equivalent to cacheForever()
).
cacheTime
- the cache TTL; null to use the defaultpublic PersistentDataStoreBuilder cacheMillis(long millis)
cacheTime(Duration)
with a duration in milliseconds.millis
- the cache TTL in millisecondspublic PersistentDataStoreBuilder cacheSeconds(long seconds)
cacheTime(Duration)
with a duration in seconds.seconds
- the cache TTL in secondspublic PersistentDataStoreBuilder cacheForever()
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.
public PersistentDataStoreBuilder staleValuesPolicy(PersistentDataStoreBuilder.StaleValuesPolicy staleValuesPolicy)
PersistentDataStoreBuilder.StaleValuesPolicy.EVICT
. This property has no effect if caching is disabled.staleValuesPolicy
- a PersistentDataStoreBuilder.StaleValuesPolicy
constantpublic PersistentDataStoreBuilder recordCacheStats(boolean recordCacheStats)
If set to true, this makes caching statistics available through the DataStoreStatusProvider
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.recordCacheStats
- true to record caching statiistics