anchor.diff:    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} ]).
   
  
positive.code: -define(MIN_CACHE_SECONDS_DEFAULT, 300).
  -define(MAX_CACHE_SIZE, 10000).
  
  
  -spec lookup(Host::string()) -> tuple() | 'undefined' | string().
  lookup (Host) ->
    %% Attempt cache lookup.
    {WantRefresh, CachedIPAddrs, Now} =
      try ets:lookup(?MODULE, Host) of
        [] ->                                     % Not in cache.
          {true, undefined, lhttpc_dns:os_timestamp()};
        [{_, IPAddrs0, Expiration}] ->            % Cached but maybe stale.
          Now0 = lhttpc_dns:os_timestamp(),
          {Now0 >= Expiration, IPAddrs0, Now0}
      catch
        error:badarg ->
          {fallback, undefined, undefined}
      end,
  
    case WantRefresh of
  
negative.code:       choose_addr(CachedIPAddrs);
      true ->
        %% Cached lookup failed.  Perform lookup and cache results.
        {{IPAddrs, TTL}, Counts} =
          case lhttpc_dns:lookup_uncached(Host) of
            FailureLookup = {undefined, _} ->
              %% If the lookup fails but we have a stale cached result, keep it.
              UpdatedFailureLookup =
                case CachedIPAddrs of
                  undefined -> FailureLookup;
                  _         -> {CachedIPAddrs, min_cache_seconds()}
                end,
              {UpdatedFailureLookup, count_failure(CachedCounts)};
            SuccessLookup ->
              {SuccessLookup, count_success(CachedCounts, Now)}
          end,
        ets_insert_bounded(?MODULE, {Host, IPAddrs, timestamp_add_seconds(Now, TTL), Counts}),
        choose_addr(IPAddrs)
    end.
  
  