Proposal to add another option to configure the DNS cache

Sergey Bylokhov bylokhov at amazon.com
Fri Mar 10 04:47:02 UTC 2023


Hello

I would like to discuss the possible improvement of the DNS cache which is implemented in the shared 
code in "InetAddress.java":
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/net/InetAddress.java#L923
and controlled by the "InetAddressCachePolicy.java"
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/sun/net/InetAddressCachePolicy.java#L32

At the moment this cache can be configured by the application using the following two properties:
   (1) "networkaddress.cache.ttl" - cache policy for successful lookups
   (2) "networkaddress.cache.negative.ttl" - cache policy for negative lookups

These properties are useful but have one limitation as the TTL value is directly related to storing 
the record in the cache.

  - If an application wants to always have up-to-date data, it can always make requests to the 
server. But in this case, "negative responses"/errors can break the application.
  - If an application wants to make fewer requests to the server, and the DNS value changes rarely 
it can set a long timeout. But obviously, this will lead to the record will be rarely updated. And 
if at the time of the update the failure happens - our cache will become useless as we will cache a 
negative response.

It would be good to have benefits from both cases above without the negative part. I propose to 
implement the possibility to update/refresh entries in the cache periodically without deleting them.

This can be implemented by an additional property like "networkaddress.extended.cache.ttl".

Consider an example: the application may set the next values "networkaddress.cache.ttl" = 60 and 
"networkaddress.extended.cache.ttl" = 600. This will cache the record for 1 minute and then, if the 
next request is successful, re-cache the value for another 1 minute, and so on. If the next request 
is unsuccessful, it will fallback to the cached record for 9 minutes(10 minutes from the last 
successful lookup), and finally after a few attempts to update/re-cache the value will be deleted 
from the cache.

Default behavior when this new property is not set will not be changed.

Thoughts?

-- 
Best regards, Sergey.


More information about the net-dev mailing list