public abstract class PersistentDataStoreBuilder extends java.lang.Object implements FeatureStoreFactory, DiagnosticDescription
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(FeatureStoreFactory)
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
ttlSeconds()
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)
.
Modifier and Type | Class and Description |
---|---|
static class |
PersistentDataStoreBuilder.StaleValuesPolicy
Possible values for
staleValuesPolicy(StaleValuesPolicy) . |
Modifier and Type | Field and Description |
---|---|
protected CacheMonitor |
cacheMonitor |
protected FeatureStoreCacheConfig |
caching |
static int |
DEFAULT_CACHE_TTL_SECONDS
The default value for the cache TTL.
|
protected PersistentDataStoreFactory |
persistentDataStoreFactory |
Modifier | Constructor and Description |
---|---|
protected |
PersistentDataStoreBuilder(PersistentDataStoreFactory persistentDataStoreFactory)
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(long, TimeUnit) with TimeUnit.MILLISECONDS . |
PersistentDataStoreBuilder |
cacheMonitor(CacheMonitor cacheMonitor)
Provides a conduit for an application to monitor the effectiveness of the in-memory cache.
|
PersistentDataStoreBuilder |
cacheSeconds(long seconds)
Shortcut for calling
cacheTime(long, TimeUnit) with TimeUnit.SECONDS . |
PersistentDataStoreBuilder |
cacheTime(long cacheTime,
java.util.concurrent.TimeUnit cacheTimeUnit)
Specifies the cache TTL.
|
PersistentDataStoreBuilder |
noCaching()
Specifies that the SDK should not use an in-memory cache for the persistent data store.
|
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
createFeatureStore
describeConfiguration
public static final int DEFAULT_CACHE_TTL_SECONDS
protected final PersistentDataStoreFactory persistentDataStoreFactory
protected FeatureStoreCacheConfig caching
protected CacheMonitor cacheMonitor
protected PersistentDataStoreBuilder(PersistentDataStoreFactory persistentDataStoreFactory)
persistentDataStoreFactory
- the factory implementation for the specific data store typepublic PersistentDataStoreBuilder noCaching()
public PersistentDataStoreBuilder cacheTime(long cacheTime, java.util.concurrent.TimeUnit cacheTimeUnit)
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 in whatever units you wishcacheTimeUnit
- the time unitpublic PersistentDataStoreBuilder cacheMillis(long millis)
cacheTime(long, TimeUnit)
with TimeUnit.MILLISECONDS
.millis
- the cache TTL in millisecondspublic PersistentDataStoreBuilder cacheSeconds(long seconds)
cacheTime(long, TimeUnit)
with TimeUnit.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 cacheMonitor(CacheMonitor cacheMonitor)
Create an instance of CacheMonitor
; retain a reference to it, and also pass it to this
method when you are configuring the persistent data store. The store will use
CacheMonitor.setSource(java.util.concurrent.Callable)
to make the caching
statistics available through that CacheMonitor
instance.
Note that turning on cache monitoring may slightly decrease performance, due to the need to record statistics for each cache operation.
Example usage:
CacheMonitor cacheMonitor = new CacheMonitor();
LDConfig config = new LDConfig.Builder()
.dataStore(Components.persistentDataStore(Redis.dataStore()).cacheMonitor(cacheMonitor))
.build();
// later...
CacheMonitor.CacheStats stats = cacheMonitor.getCacheStats();
cacheMonitor
- an instance of CacheMonitor