Package io.netty.resolver.dns
Class DefaultDnsCache
java.lang.Object
io.netty.resolver.dns.DefaultDnsCache
- All Implemented Interfaces:
DnsCache
Default implementation of
DnsCache
, backed by a ConcurrentMap
.
If any additional DnsRecord
is used, no caching takes place.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
private final int
private final int
private final Cache
<DefaultDnsCache.DefaultDnsCacheEntry> -
Constructor Summary
ConstructorsConstructorDescriptionCreate a cache that respects the TTL returned by the DNS server and doesn't cache negative responses.DefaultDnsCache
(int minTtl, int maxTtl, int negativeTtl) Create a cache. -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
Cache the resolution failure for a given hostname.cache
(String hostname, DnsRecord[] additionals, InetAddress address, long originalTtl, EventLoop loop) Create a newDnsCacheEntry
and cache a resolved address for a given hostname.void
clear()
Clears all the resolved addresses cached by this resolver.boolean
Clears the resolved addresses of the specified host name from the cache of this resolver.private static Throwable
copyThrowable
(Throwable error) private static boolean
emptyAdditionals
(DnsRecord[] additionals) List
<? extends DnsCacheEntry> Return the cached entries for the given hostname.int
maxTtl()
Returns the maximum TTL of the cached DNS resource records (in seconds).int
minTtl()
Returns the minimum TTL of the cached DNS resource records (in seconds).int
Returns the TTL of the cache for the failed DNS queries (in seconds).toString()
-
Field Details
-
resolveCache
-
minTtl
private final int minTtl -
maxTtl
private final int maxTtl -
negativeTtl
private final int negativeTtl
-
-
Constructor Details
-
DefaultDnsCache
public DefaultDnsCache()Create a cache that respects the TTL returned by the DNS server and doesn't cache negative responses. -
DefaultDnsCache
public DefaultDnsCache(int minTtl, int maxTtl, int negativeTtl) Create a cache.- Parameters:
minTtl
- the minimum TTLmaxTtl
- the maximum TTLnegativeTtl
- the TTL for failed queries
-
-
Method Details
-
minTtl
public int minTtl()Returns the minimum TTL of the cached DNS resource records (in seconds).- See Also:
-
maxTtl
public int maxTtl()Returns the maximum TTL of the cached DNS resource records (in seconds).- See Also:
-
negativeTtl
public int negativeTtl()Returns the TTL of the cache for the failed DNS queries (in seconds). The default value is0
, which disables the cache for negative results. -
clear
public void clear()Description copied from interface:DnsCache
Clears all the resolved addresses cached by this resolver. -
clear
Description copied from interface:DnsCache
Clears the resolved addresses of the specified host name from the cache of this resolver. -
emptyAdditionals
-
get
Description copied from interface:DnsCache
Return the cached entries for the given hostname. -
cache
public DnsCacheEntry cache(String hostname, DnsRecord[] additionals, InetAddress address, long originalTtl, EventLoop loop) Description copied from interface:DnsCache
Create a newDnsCacheEntry
and cache a resolved address for a given hostname.- Specified by:
cache
in interfaceDnsCache
- Parameters:
hostname
- the hostnameadditionals
- the additional recordsaddress
- the resolved addressoriginalTtl
- the TTL as returned by the DNS serverloop
- theEventLoop
used to register the TTL timeout- Returns:
- The
DnsCacheEntry
corresponding to this cache entry.
-
cache
public DnsCacheEntry cache(String hostname, DnsRecord[] additionals, Throwable cause, EventLoop loop) Description copied from interface:DnsCache
Cache the resolution failure for a given hostname. Be aware this won't be called with timeout / cancel / transport exceptions.- Specified by:
cache
in interfaceDnsCache
- Parameters:
hostname
- the hostnameadditionals
- the additional recordscause
- the resolution failureloop
- theEventLoop
used to register the TTL timeout- Returns:
- The
DnsCacheEntry
corresponding to this cache entry, ornull
if this cache doesn't support caching failed responses.
-
toString
-
appendDot
-
copyThrowable
-