anchor.diff:      {reply, ok, State#state{max_cache_size = NewSize}};
   
   handle_call({new_max_cache_size, NewSize}, _From, State) ->
  -    lists:foreach(
  -        fun(_) ->
  -            MruTime = ets:last(?BY_ATIME),
  -            [{MruTime, UserName}] = ets:lookup(?BY_ATIME, MruTime),
  -            true = ets:delete(?BY_ATIME, MruTime),
  -            true = ets:delete(?BY_USER, UserName)
  -        end,
  -        lists:seq(1, State#state.cache_size - NewSize)
  -    ),
  +    free_mru_cache_entries(State#state.cache_size - NewSize),
       {reply, ok, State#state{max_cache_size = NewSize, cache_size = NewSize}};
   
   handle_call({fetch, UserName}, _From, State) ->
  
positive.code:     true = ets:insert(?BY_USER, {UserName, {Credentials, ATime}}),
      State#state{cache_size = couch_util:get_value(size, ets:info(?BY_USER))}.
  
  
  free_mru_cache_entry() ->
      case ets:last(?BY_ATIME) of
      '$end_of_table' ->
          ok;  % empty cache
      MruTime ->
          [{MruTime, UserName}] = ets:lookup(?BY_ATIME, MruTime),
          true = ets:delete(?BY_ATIME, MruTime),
          true = ets:delete(?BY_USER, UserName)
      end.
  
  
  cache_hit(UserName, Credentials, ATime) ->
  
negative.code:     State#state{cache_size = 0}.
  
  
  add_cache_entry(_, _, _, #state{max_cache_size = 0} = State) ->
      State;
  add_cache_entry(UserName, Credentials, ATime, State) ->
      case State#state.cache_size >= State#state.max_cache_size of
      true ->
  