Package com.mixpanel.android.mpmetrics
Class VariantLookupPolicy
java.lang.Object
com.mixpanel.android.mpmetrics.VariantLookupPolicy
- Direct Known Subclasses:
VariantLookupPolicy.NetworkFirst,VariantLookupPolicy.NetworkOnly,VariantLookupPolicy.PersistenceUntilNetworkSuccess
Configures how the SDK resolves feature flag variants relative to the on-disk persistence
layer and the network.
Three strategies are supported:
VariantLookupPolicy.NetworkOnly- never read or write persisted variants. Variant lookups always wait for the network call. This is the default and matches behavior prior to the introduction of variant persistence. Construction also wipes any stale on-disk blob left over from a prior persisting configuration.VariantLookupPolicy.PersistenceUntilNetworkSuccess- serve persisted variants immediately when available, and only block on the network if no persisted variants exist for the current user. The network call still runs in the background to refresh. Persisted entries older thanpersistenceTtlMillisare not served.VariantLookupPolicy.NetworkFirst- prefer fresh values from the network, but fall back to persisted variants when the network call fails. Persisted entries older thanpersistenceTtlMillisare not served.
Construct instances via the static factories rather than new:
VariantLookupPolicy.networkOnly()
VariantLookupPolicy.persistenceUntilNetworkSuccess(TimeUnit.HOURS.toMillis(24))
VariantLookupPolicy.networkFirst(TimeUnit.HOURS.toMillis(24))
This class is intentionally Java 8 compatible (no sealed keyword) even though the
module compiles at source level 17. The package-private constructor prevents external
subclassing while leaving the type open for instanceof dispatch at consumer sites.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classStrategy that prefers a fresh network response but falls back to persisted variants when the network call fails.static final classStrategy that never consults persisted variants.static final classStrategy that serves persisted variants immediately when available and only waits on the network when no persisted entry exists. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault persistence TTL applied bypersistenceUntilNetworkSuccess()andnetworkFirst()when no explicit TTL is provided. -
Method Summary
Modifier and TypeMethodDescriptionReturns aVariantLookupPolicy.NetworkFirststrategy with theDEFAULT_PERSISTENCE_TTL_MILLIS.networkFirst(long persistenceTtlMillis) Returns aVariantLookupPolicy.NetworkFirststrategy with the given persistence TTL.Returns the singletonVariantLookupPolicy.NetworkOnlystrategy.Returns aVariantLookupPolicy.PersistenceUntilNetworkSuccessstrategy with theDEFAULT_PERSISTENCE_TTL_MILLIS.persistenceUntilNetworkSuccess(long persistenceTtlMillis) Returns aVariantLookupPolicy.PersistenceUntilNetworkSuccessstrategy with the given persistence TTL.
-
Field Details
-
DEFAULT_PERSISTENCE_TTL_MILLIS
public static final long DEFAULT_PERSISTENCE_TTL_MILLISDefault persistence TTL applied bypersistenceUntilNetworkSuccess()andnetworkFirst()when no explicit TTL is provided. 24 hours.- See Also:
-
-
Method Details
-
networkOnly
Returns the singletonVariantLookupPolicy.NetworkOnlystrategy. Identity comparison is meaningful — every call returns the same instance. -
persistenceUntilNetworkSuccess
@NonNull public static VariantLookupPolicy.PersistenceUntilNetworkSuccess persistenceUntilNetworkSuccess()Returns aVariantLookupPolicy.PersistenceUntilNetworkSuccessstrategy with theDEFAULT_PERSISTENCE_TTL_MILLIS. -
persistenceUntilNetworkSuccess
@NonNull public static VariantLookupPolicy.PersistenceUntilNetworkSuccess persistenceUntilNetworkSuccess(long persistenceTtlMillis) Returns aVariantLookupPolicy.PersistenceUntilNetworkSuccessstrategy with the given persistence TTL.- Parameters:
persistenceTtlMillis- maximum age, in milliseconds, of a persisted variant set before it is not served. Non-positive values are treated as a misconfiguration — the SDK substitutesnetworkOnly()at init (with a warning logged), since persistence with no meaningful TTL does no useful work.
-
networkFirst
Returns aVariantLookupPolicy.NetworkFirststrategy with theDEFAULT_PERSISTENCE_TTL_MILLIS. -
networkFirst
Returns aVariantLookupPolicy.NetworkFirststrategy with the given persistence TTL.- Parameters:
persistenceTtlMillis- maximum age, in milliseconds, of a persisted variant set before it is not served. Non-positive values are treated as a misconfiguration — the SDK substitutesnetworkOnly()at init (with a warning logged), since persistence with no meaningful TTL does no useful work.
-