anchor.diff:                                lists:member(B, Buckets) and
                                     lists:member({H, P}, Servers)
                             end, OldTopkeys),
  -    {noreply, State#state{vals=Vals, topkeys=Topkeys}};
  +    Now = erlang:now(),
  +    Cache = dict:filter(fun (_K, {TS, _V}) -> timer:now_diff(Now, TS) < ?CACHE_MAXAGE end,
  +                        State#state.cache),
  +    {noreply, State#state{vals=Vals, topkeys=Topkeys, cache=Cache}};
   handle_info(Info, State) ->
       error_logger:info_msg("Just received ~p~n", [Info]),
       {noreply, State}.
  
positive.code: -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
           terminate/2, code_change/3]).
  
  -record(state, {vals, topkeys}).
  
  start_link() ->
      gen_server:start_link({global, ?MODULE}, ?MODULE, [], []).
  
  init([]) ->
      timer:send_interval(60000, garbage_collect),
      {ok, #state{vals=dict:new(), topkeys=dict:new()}}.
  
  handle_call({get, Hostname, Port, Bucket, Count}, _From, State) ->
      Reply = (catch {ok, ringdict:to_dict(Count,
                               dict:fetch({Hostname, Port, Bucket},
                                          State#state.vals))}),
      {reply, Reply, State};
  handle_call({get, Hostname, Port, Count}, _From, State) ->
      Reply =
          (catch {ok, dict:fold(
                   fun ({H, P, _B}, V, A) ->
                           case {H, P} of
                               {Hostname, Port} ->
                                   combine_stats(Count, V, A);
                               _ -> A
                           end
                   end,
                   dict:new(),
                   State#state.vals)}),
      {reply, Reply, State};
  handle_call({get, Bucket, Count}, _From, State) ->
      Reply =
          (catch {ok, dict:fold(
                   fun ({_H, _P, B}, V, A) ->
                           case B of
                               Bucket ->
                                   combine_stats(Count, V, A);
                               _ -> A
                           end
                   end,
                   dict:new(),
                   State#state.vals)}),
      {reply, Reply, State};
  handle_call({get, Count}, _From, State) ->
      Reply =
          (catch {ok, dict:fold(
                   fun ({_H, _P, _B}, V, A) ->
                           combine_stats(Count, V, A)
                   end,
                   dict:new(),
                   State#state.vals)}),
      {reply, Reply, State};
  handle_call({get_topkeys, Bucket}, _From, State) ->
      Reply = (catch {ok, dict:fold(
              fun ({_Host, _Port, B}, Dict, Acc)->
                      case B of
                          Bucket ->
                              dict:merge(
                                  fun (_Key, Value1, _Value2) ->
                                          Value1
                                  end,
                                  Dict, Acc);
                          _ -> Acc
                      end
              end,
              dict:new(),
              State#state.topkeys)}),
      {reply, Reply, State}.
  
  handle_cast({received, T, Hostname, Port, Bucket, Stats}, State) ->
      TS = dict:store(t, T, Stats),
  
negative.code: classify("binding_protocol") -> false;
  classify(_) -> true.
  
  cache_lookup(Key, Cache, MaxAge, F) ->
      Now = erlang:now(),
      case dict:find(Key, Cache) of
      {ok, {Timestamp, CachedValue}} ->
          case timer:now_diff(Now, Timestamp) < MaxAge of
          true -> {CachedValue, Cache};
          false -> % expired
              NewValue = F(),
              {NewValue, dict:store(Key, {Now, NewValue}, Cache)}
          end;
      error ->
          NewValue = F(),
          {NewValue, dict:store(Key, {Now, NewValue}, Cache)}
      end.
  
  do_get(Hostname, Port, Count, State) ->
      (catch {ok, dict:fold(
               fun ({H, P, _B}, V, A) ->
                       case {H, P} of
                           {Hostname, Port} ->
                               combine_stats(Count, V, A);
                           _ -> A
                       end
               end,
               dict:new(),
               State#state.vals)}).
  
  do_get(Bucket, Count, State) ->
      (catch {ok, dict:fold(
               fun ({_H, _P, B}, V, A) ->
                       case B of
                           Bucket ->
                               combine_stats(Count, V, A);
                           _ -> A
                       end
               end,
               dict:new(),
               State#state.vals)}).
  
  do_get(Count, State) ->
      (catch {ok, dict:fold(
               fun ({_H, _P, _B}, V, A) ->
                       combine_stats(Count, V, A)
               end,
               dict:new(),
               State#state.vals)}).
  
  do_get_topkeys(Bucket, State) ->
      (catch {ok, dict:fold(
              fun ({_Host, _Port, B}, Dict, Acc)->
                      case B of
                          Bucket ->
                              dict:merge(
                                  fun (_Key, Value1, _Value2) ->
                                          Value1
                                  end,
                                  Dict, Acc);
                          _ -> Acc
                      end
              end,
              dict:new(),
              State#state.topkeys)}).
  %
  % API
  %
  