4

Currently I am working on an Android project. I have a doubt regrading java level DNS caching. Through search, I came to know that through calling the below mentioned functions we can achieve it.

 System.setProperty( "networkaddress.cache.ttl", "0" );
 System.setProperty( "networkaddress.cache.negative.ttl", "0" );

Based on this, it caches name look up data or not. I want to know the purpose or impact because of this property.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
intrepidkarthi
  • 3,104
  • 8
  • 42
  • 75

2 Answers2

3

The purpose is to do less DNS requests. That results in quicker download because the IP for a hostname is allready in cache.

This are Java system properties that have effect directly to the standard network library. It allows you to tune the Java level DNS caching.

As all caching, caching has sometimes not desireable effects, such as the cache get updated late when some DNS entries has changed.

I consider values such 0 (no cache) or -1 (cache forever) only for testing purpose.

PeterMmm
  • 24,152
  • 13
  • 73
  • 111
0

Also I don't think you can set the properties as above. On the JVMs you need to use

java.security.Security.setProperty("networkaddress.cache.ttl" , "10");

(not sure about Android)

Henry Story
  • 2,116
  • 1
  • 17
  • 28