DnsOptions.StaleDnsOptions.Builder

class DnsOptions.StaleDnsOptions.Builder


Builder for StaleDnsOptions.

Summary

Public functions

DnsOptions.StaleDnsOptions.Builder!
allowCrossNetworkUsage(allowCrossNetworkUsage: Boolean)

Sets whether to return results originating from other networks or not.

DnsOptions.StaleDnsOptions!

Creates and returns the final StaleDnsOptions instance, based on the values in this builder.

DnsOptions.StaleDnsOptions.Builder!

Same as setFreshLookupTimeoutMillis but using java.time.Duration.

DnsOptions.StaleDnsOptions.Builder!
setFreshLookupTimeoutMillis(freshLookupTimeoutMillis: Long)

Sets how long (in milliseconds) to wait for a DNS request to return before using a stale result instead.

DnsOptions.StaleDnsOptions.Builder!

Same as setMaxExpiredDelayMillis but using java.time.Duration.

DnsOptions.StaleDnsOptions.Builder!
setMaxExpiredDelayMillis(maxExpiredDelayMillis: Long)

Sets how long (in milliseconds) past expiration to consider using expired results.

DnsOptions.StaleDnsOptions.Builder!
useStaleOnNameNotResolved(useStaleOnNameNotResolved: Boolean)

Sets whether to allow use of stale DNS results when network resolver fails to resolve the hostname.

Public functions

allowCrossNetworkUsage

fun allowCrossNetworkUsage(allowCrossNetworkUsage: Boolean): DnsOptions.StaleDnsOptions.Builder!

Sets whether to return results originating from other networks or not. Normally, Cronet clears the DNS cache entirely when switching connections, e.g. between two Wi-Fi networks or from Wi-Fi to 4G.

Returns
DnsOptions.StaleDnsOptions.Builder!

the builder for chaining

build

fun build(): DnsOptions.StaleDnsOptions!

Creates and returns the final StaleDnsOptions instance, based on the values in this builder.

setFreshLookupTimeout

@RequiresApi(value = VERSION_CODES.O)
fun setFreshLookupTimeout(freshLookupTimeout: Duration): DnsOptions.StaleDnsOptions.Builder!

Same as setFreshLookupTimeoutMillis but using java.time.Duration.

Returns
DnsOptions.StaleDnsOptions.Builder!

the builder for chaining

setFreshLookupTimeoutMillis

fun setFreshLookupTimeoutMillis(freshLookupTimeoutMillis: Long): DnsOptions.StaleDnsOptions.Builder!

Sets how long (in milliseconds) to wait for a DNS request to return before using a stale result instead. If set to zero, returns stale results instantly but continues the DNS request in the background to update the cache.

Returns
DnsOptions.StaleDnsOptions.Builder!

the builder for chaining

setMaxExpiredDelay

@RequiresApi(value = VERSION_CODES.O)
fun setMaxExpiredDelay(maxExpiredDelay: Duration): DnsOptions.StaleDnsOptions.Builder!

Same as setMaxExpiredDelayMillis but using java.time.Duration.

Returns
DnsOptions.StaleDnsOptions.Builder!

the builder for chaining

setMaxExpiredDelayMillis

fun setMaxExpiredDelayMillis(maxExpiredDelayMillis: Long): DnsOptions.StaleDnsOptions.Builder!

Sets how long (in milliseconds) past expiration to consider using expired results. Setting the value to zero means expired records can be used indefinitely.

Returns
DnsOptions.StaleDnsOptions.Builder!

the builder for chaining

useStaleOnNameNotResolved

fun useStaleOnNameNotResolved(useStaleOnNameNotResolved: Boolean): DnsOptions.StaleDnsOptions.Builder!

Sets whether to allow use of stale DNS results when network resolver fails to resolve the hostname.

Depending on the use case, if Cronet quickly sees a fresh failure, it may be desirable to use the failure as it is technically the fresher result, and we had such a fresh result quickly; or, prefer having any result (even if stale) to use over having a failure.

Returns
DnsOptions.StaleDnsOptions.Builder!

the builder for chaining