DnsOptions.Builder

class DnsOptions.Builder


Builder for DnsOptions.

Summary

Public functions

DnsOptions!

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

DnsOptions.Builder!

Sets whether to use stale DNS results at all.

DnsOptions.Builder!
persistHostCache(persistHostCache: Boolean)

Sets whether the DNS cache should be persisted to disk.

DnsOptions.Builder!

Sets whether Cronet should use stale cached DNS records to pre-establish connections.

DnsOptions.Builder!
@RequiresApi(api = VERSION_CODES.O)
setPersistDelay(persistToDiskPeriod: Duration)

Same as setPersistHostCachePeriodMillis but using java.time.Duration.

DnsOptions.Builder!
setPersistHostCachePeriodMillis(persistHostCachePeriodMillis: Long)

Sets the minimum period between subsequent writes to disk for DNS cache persistence.

DnsOptions.Builder!
DnsOptions.Builder!

Sets detailed configuration for stale DNS.

DnsOptions.Builder!

Public functions

build

fun build(): DnsOptions!

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

enableStaleDns

fun enableStaleDns(enable: Boolean): DnsOptions.Builder!

Sets whether to use stale DNS results at all.

Returns
DnsOptions.Builder!

the builder for chaining

persistHostCache

fun persistHostCache(persistHostCache: Boolean): DnsOptions.Builder!

Sets whether the DNS cache should be persisted to disk.

Only relevant if setStoragePath is set.

Returns
DnsOptions.Builder!

the builder for chaining

preestablishConnectionsToStaleDnsResults

@DnsOptions.Experimental
fun preestablishConnectionsToStaleDnsResults(enable: Boolean): DnsOptions.Builder!

Sets whether Cronet should use stale cached DNS records to pre-establish connections.

If enabled, Cronet will optimistically pre-establish connections to servers that matched the hostname at some point in the past and were cached but the cache entry expired. Such connections won't be used further until a new DNS lookup confirms the cached record was up to date.

To use cached DNS records straight away, use enableStaleDns and StaleDnsOptions configuration options.

This option may not be available for all networking protocols.

Returns
DnsOptions.Builder!

the builder for chaining

setPersistDelay

@RequiresApi(api = VERSION_CODES.O)
fun setPersistDelay(persistToDiskPeriod: Duration): DnsOptions.Builder!

Same as setPersistHostCachePeriodMillis but using java.time.Duration.

Returns
DnsOptions.Builder!

the builder for chaining

setPersistHostCachePeriodMillis

fun setPersistHostCachePeriodMillis(persistHostCachePeriodMillis: Long): DnsOptions.Builder!

Sets the minimum period between subsequent writes to disk for DNS cache persistence.

Only relevant if persistHostCache is set to true.

Returns
DnsOptions.Builder!

the builder for chaining

setStaleDnsOptions

@DnsOptions.Experimental
fun setStaleDnsOptions(
    staleDnsOptionsBuilder: DnsOptions.StaleDnsOptions.Builder!
): DnsOptions.Builder!

setStaleDnsOptions

fun setStaleDnsOptions(staleDnsOptions: DnsOptions.StaleDnsOptions!): DnsOptions.Builder!

Sets detailed configuration for stale DNS. Only relevant if enableStaleDns is set.

Returns
DnsOptions.Builder!

this builder for chaining.

useBuiltInDnsResolver

fun useBuiltInDnsResolver(enable: Boolean): DnsOptions.Builder!