Subject: Re: Adding TTL information to gethostbyname() and friends
To: Andrew Brown <atatat@atatdot.net>
From: Ian Lance Taylor <ian@airs.com>
List: tech-net
Date: 06/02/2003 10:16:54
Andrew Brown <atatat@atatdot.net> writes:

> then again, the name service functions aren't really designed for
> people who want caching.  imho, people who want caching should do dns
> themselves, probably using routines no more complex than res_mkquery()
> and dn_expand().  those people that want a simple interface should use
> it as that, and trust some other component (local name server, nscd,
> lwresd, or whatever) to do the caching.

In principle, I agree.  In practice, programs do not work that way.
In particular, web browsers do not work that way, as I've established
by looking at the Mozilla source code and by experimenting with IE.

Browsers do not always query a cache because for many people the DNS
cache is on the other side of a slow modem link.  To use the resolver
cache properly would imply a DNS query for every web page download.
The round trip time for the DNS query would add measurable time to the
download.  To avoid that time, browsers maintain their own cache, but
because they do not use the correct TTL, the cache is slightly
incorrect.

In principle browsers could use their own DNS lookup functions to get
the TTL.  But they also need to consider /etc/hosts and NIS
information, so they just use gethostbyname() and friends.

Ian