anchor.diff:  %% @doc Caching module. Uses ETS to cache cache output.
   -module(cache).
   -export([cached_fun/2, create_table/0, delete_table/0]).
  +-include_lib("stdlib/include/ms_transform.hrl").
   
   %% @doc LIFETIME defines, in seconds, cache lifetime
   -ifdef(TEST).
  
positive.code:     F = fun(K) -> K ++ "demo" end, %A mock function
      timer:sleep((?LIFETIME+1)*1000),
      ?assertEqual(cached_fun(F, "127"), {"127demo", expire}).
  
  delete_table_test() ->
      delete_table().
  
negative.code:     {MegaSecs, Secs, _MicroSecs} = os:timestamp(),
      MegaSecs*1000000 + Secs.
  
  %% @doc Expires old content
  -spec cache_flush() -> ok.
  cache_flush() ->
      Now = now_secs(),
      Selector = ets:fun2ms(fun({K, Expiry, _Res}) 
              when Expiry < Now -> true end),
      ets:select_delete(simple_cache, Selector),
      ok.
  
  %% @doc For a key K, caches the output of F(K).
  -spec cached_fun(function(), list()) -> {_, 'expire' | 'hit' | 'miss'}.
  cached_fun(F, K) ->
      Now = now_secs(),
      case ets:lookup(simple_cache, K) of
      [] ->  %Not present in cache
          cache_flush(), %Flushing on add ensures size is managed
          FuncRes = F(K),
          ets:insert(simple_cache, {K, Now+?LIFETIME, FuncRes}),
          {FuncRes, miss};
  