喜糖

移动开发工程师 。涉及 android、ios、jni

导航

DNS加速

Posted on 2013-09-21 22:59  喜糖  阅读(649)  评论(0编辑  收藏  举报

http://elingwange.iteye.com/blog/1563497

http://blog.csdn.net/lize1988/article/details/10404645

 

java.net.InetAddress内部的缓存我们没有办法控制。4.0以前是永久缓存,4.0以后是只缓存2s。也就是说4.0以前通过设置虚拟机TTL没有用,因为java.net.InetAddress永久缓存了。

下面是android api InetAddress 里的原话:

 

DNS caching

In Android 4.0 (Ice Cream Sandwich) and earlier, DNS caching was performed both by InetAddress and by the C library, which meant that DNS TTLs could not be honored correctly.In later releases, caching is done solely by the C library and DNS TTLs are honored.

 

 

 

在控制DNS缓存时有两点需要注意:

    1. 可以根据实际情况来设置networkaddress.cache.ttl属性的值。一般将这个属性的值设为-1.但如果访问的是动态映射的域名(如使用动态域名服务将域名映射成ADSL的动态IP), 就可能产生IP地址变化后,客户端得到的还是原来的IP地址的情况。

    2. 在设置networkaddress.cache.negative.ttl属性值时最好不要将它设为-1,否则如果一个域名因为暂时的故障而无法访问,那么程序再次访问这个域名时,即使这个域名恢复正常,程序也无法再访问这个域名了。除非重新运行程序。