anchor.diff:                  lists:foldl(fun (Answer, {IPAddrAcc, MinTTL}) ->
                                   [ IPAddr, TTL ] = inet_dns:rr(Answer, [ data, ttl ]),
                                   %% Cache a successful lookup for an additional
  -                                %% 2 seconds.
  +                                %% 2 seconds, to avoid refetching an entry
  +                                %% from the local DNS resolver right before it
  +                                %% refreshes its own cache.
                                   {[ IPAddr | IPAddrAcc ], min(MinTTL, TTL + ?SUCCESS_CACHE_EXTRA_SECONDS)}
                               end, {[], ?MAX_CACHE_SECONDS}, Answers),
                 {list_to_tuple(IPAddrs), max(TTL, min_cache_seconds())}
  
positive.code:       choose_addr(CachedIPAddrs);
      true ->
        %% Cached lookup failed.  Perform lookup and cache results.
        {IPAddrs, TTL} =
          case lhttpc_dns:lookup_uncached(Host) of
            FailureLookup = {undefined, _} ->
              %% If the lookup fails but we have a stale cached result, keep it.
              case CachedIPAddrs of
                undefined -> FailureLookup;
                _         -> {CachedIPAddrs, min_cache_seconds()}
              end;
            SuccessLookup -> SuccessLookup
          end,
        ets_insert_bounded(?MODULE, {Host, IPAddrs, timestamp_add_seconds(Now, TTL)}),
        choose_addr(IPAddrs)
    end.
  
  
negative.code:   end.
  
  
  -spec count_success(Counts::lhttpc_dns_counts()|'undefined', Now::erlang:timestamp()) -> lhttpc_dns_counts().
  count_success({SuccessCount, FailureCount, _FailuresSinceLastSuccessCount, _LastSuccessTime}, Now) ->
    {SuccessCount + 1, FailureCount, 0, Now};
  count_success(undefined, Now) ->
    {1, 0, 0, Now}.
  
  
  -spec count_failure(Counts::lhttpc_dns_counts()|'undefined') -> lhttpc_dns_counts().
  count_failure({SuccessCount, FailureCount, FailuresSinceLastSuccessCount, LastSuccessTime}) ->
    {SuccessCount, FailureCount + 1, FailuresSinceLastSuccessCount + 1, LastSuccessTime};
  count_failure(undefined) ->
    {0, 1, 1, undefined}.
  
  
  create_table() ->
    ets:new(?MODULE, [ set, public, named_table, {read_concurrency, true}, {write_concurrency, true} ]).
  
  