It simply is not possible to disable the cache from Java.
The fixes/enhancements you mention are already planned for a future release,
but didn't happen yet for various reasons.

sorry about that.

On Thu, Jan 15, 2009 at 12:43 PM, Greg White <[email protected]>wrote:

> All,
>
> I've recently been bit by some DNS caching issues and am wondering if there
> is some way around them.  The source seems to say 'no', but perhaps I'm
> missing something.
>
> I'm trying to resolve hostnames using a couple of different methods:
>
>     new InetSocketAddress(host, port) // The 'normal ' way
>
> and
>
>     InetAddress[] addresses = InetAddress.getAllByName(host); // And this
> way to bypass the cache in InetAddress
>
> I start the emulator with -dns-server pointing at my host which is running
> dnsmasq set to return records with a TTL of 1 second.  This allows me to
> tweak the returned DNS values to simulate a DNS change.
>
> In each case, I'm doing this to (try) to disable the cache.  I'm doing both
> the generally accepted method (Security) and what PriviAction seems to be
> actually doing (System).
>
>         System.setProperty("networkaddress.cache.ttl", "0");
>         Security.setProperty("networkaddress.cache.ttl", "0");
>
> No luck, there is still DNS caching in place.
>
> Some poking around bionic reveals that there is a DNS cache in there, an
> MRU cache with 128 entries and a 10 minute timeout.  Sure enough, this
> matches what I am seeing exactly.
>
> There does not seem to be any way to flush this cache.
>
> I can disable it by setting an environment variable, BIONIC_DNSCACHE, to
> zero at process startup - if I can find a way to do that from Java.  That
> would be useful.
>
> While I am all for DNS caches, this 10 minute caching would seem to be
> inappropriate for a roaming device.  The problem I am trying to work around
> is that when I switch from my work network to the carrier network and vice
> versa, the DNS cache is not flushed.  We have an internal server set to
> resolve differently when you are inside the work network than when you are
> external (common enough) and this switch takes 10 full minutes to take
> effect after I switch networks.
>
> Is there some way to dump this cache short of a process restart?
>
> Neither of these caches honors TTL.  Bad caches.
>
> And there are two of them, one in Java, one in C, one on top of the other,
> which is very strange.  One would seem to be entirely sufficient.
>
> Furthermore, would it not be better to centralize these caches and flush
> them on a network change?  It would seem that it would be more efficient,
> faster and better to have all applications hitting one DNS cache, which
> could then be flushed after the DNS server changed.  It would be easy to
> configure dnsmasq to do just this - and all of the processes' DNS caches
> could be eliminated and fixed - and, presumably, this central cache could
> honor TTL.  It further appears that this could be accomplished with minimal
> code changes by setting the correct propery in Java, the right environment
> variable in C, pointing everyone at the local dnsmasq instance, and then
> configuring that on network change.
>
> Any help which anyone can offer would be greatly appreciated.
>
>
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to