anchor.diff:      {noreply, State#state{metadata=Metadata}};
   
   handle_info(flush_cache, State) ->
  -    case State#state.cache of
  -        [] -> {noreply, State};
  -        Cs ->
  -            lager:debug("flushing metric cache of ~p (~w entries)",
  -                        [State#state.path, State#state.cache_size]),
  -
  -            File = State#state.fspath,
  -            case statser_whisper:update_points(File, Cs) of
  -                ok ->
  -                    statser_instrumentation:increment(<<"committed-points">>, State#state.cache_size),
  -                    statser_instrumentation:increment(<<"writes">>),
  -                    {noreply, State#state{cache=[], cache_size=0}};
  -                _Error ->
  -                    % archive is not existing (yet)
  -                    % so dispatch a creation via rate-limiter
  -                    request_create(),
  -                    {noreply, State}
  -            end
  -    end;
  +    State0 = flush(State),
  +    {noreply, State0};
  +
  +handle_info(inactivity, State) ->
  +    Path = State#state.path,
  +    lager:info("stopping metrics handler for ~p due to inactivity", [Path]),
  +    {stop, normal, State#state{inactivity=none}};
   
   handle_info(_Info, State) ->
       {noreply, State}.
  
positive.code: 
  -define(MIN_CACHE_INTERVAL, 60).
  
  -record(state, {path, fspath, metadata, cache=[], cache_size=0}).
  
  %%%===================================================================
  %%% API
  
negative.code:     end.
  
  
  flush(#state{cache=[]} = State) ->
      State;
  flush(#state{cache=Cache, fspath=File} = State) ->
      lager:debug("flushing metric cache of ~p (~w entries)",
                  [State#state.path, State#state.cache_size]),
  
      case statser_whisper:update_points(File, Cache) of
          ok ->
              statser_instrumentation:increment(<<"committed-points">>, State#state.cache_size),
              statser_instrumentation:increment(<<"writes">>),
              State#state{cache=[], cache_size=0};
          _Error ->
              % archive is not existing (yet)
              % so dispatch a creation via rate-limiter
              request_create(),
              State
      end.
  
  
  reset_inactivity(#state{inactivity=Inactive} = State) ->
      % reset pending timer (if necessary)
      case Inactive of
          none -> ok;
          TimerRef -> erlang:cancel_timer(TimerRef, [{async, true}])
      end,
  
      % schedule new timer
      case State#state.metadata of
          #whisper_metadata{archives=[A | _]} ->
              IntervalMillis = A#whisper_archive.seconds * ?INACTIVITY_FACTOR * ?MILLIS_PER_SEC,
              Timer = erlang:send_after(IntervalMillis, self(), inactivity),
              State#state{inactivity=Timer};
          _Otherwise ->
              State#state{inactivity=none}
      end.
  
  
  %%
  %% TESTS
  %%
  