anchor.diff:  	{del_rr, RR} when is_record(RR, dns_rr) ->
   	    %% note. del_rr will handle wildcards !!!
   	    Cache = State#state.cache,
  -	    ets:match_delete(Cache, RR),
  +	    ets:delete(Cache, cache_key(RR)),
   	    {reply, ok, State};
   
   	{lookup_rr, Domain, Class, Type} ->
  -	    {reply, do_lookup_rr(Domain, Class, Type), State};
  +	    {reply, match_rr({Domain, Class, Type}), State};
   
   	{listop, Opt, Op, E} ->
   	    El = [E],
  
positive.code: do_refresh_cache('$end_of_table', _, _, OldestT) ->
      OldestT;
  do_refresh_cache(Key, CacheDb, Now, OldestT) ->
      Fun = fun(RR, T) when RR#dns_rr.tm + RR#dns_rr.ttl < Now ->
  		  ets:match_delete(CacheDb, RR),
  		  T;
  	     (#dns_rr{cnt = C}, T) when C < T ->
  		  C;
  	     (_, T) ->
  		  T
  	  end,
      Next = ets:next(CacheDb, Key),
      OldT = lists:foldl(Fun, OldestT, ets:lookup(CacheDb, Key)),
      do_refresh_cache(Next, CacheDb, Now, OldT).
  
  %% -------------------------------------------------------------------
  
negative.code:     TM = times(),
      case alloc_entry(Db, CacheDb, TM) of
  	true ->
  	    cache_rr(CacheDb, RR#dns_rr{tm = TM, cnt = TM});
  	_ ->
  	    false
      end.
  
  cache_rr(Cache, RR) ->
      ets:insert(Cache, {cache_key(RR), RR}).
  
  times() ->
      erlang:monotonic_time(second).
      %% erlang:convert_time_unit(erlang:monotonic_time() - erlang:system_info(start_time),
      %%     		     native, second).
  
  %% match and remove old entries
  
  match_rr({_, _, _} = Key) ->
      Time = times(),
      case ets:lookup(inet_cache, Key) of
  	[{_,RR}] when RR#dns_rr.ttl =:= 0 -> %% at least once
  	    ets:delete(inet_cache, Key),
  	    [RR];
  	[{_,RR}] when RR#dns_rr.tm + RR#dns_rr.ttl < Time ->
  	    ets:delete(inet_cache, Key),
  	    [];
  	[{_,RR}] ->
          %% This may fail if cache pruning removes this entry
          %% at the same time we are updating it, so ignore the result.
  	    _ = ets:update_element(inet_cache, Key, {2, RR#dns_rr{cnt = Time}}),
  	    [RR];
  	[] ->
  	    []
      end.
  
  cache_key(#dns_rr{domain = Domain, class = Class, type = Type}) ->
      {Domain, Class, Type}.
  
  %% Lower case the domain name before storage.
  %%
  