| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/io/timed_cache.erl | 16 | 
1 files changed, 16 insertions, 0 deletions
| diff --git a/src/io/timed_cache.erl b/src/io/timed_cache.erl index 66ed737..132b70f 100644 --- a/src/io/timed_cache.erl +++ b/src/io/timed_cache.erl @@ -27,6 +27,7 @@  (     [        fetch/3, +      update/4,        invalidate/3     ]  ). @@ -40,6 +41,10 @@ add_to_cache (DB, Owner, ObjectID) ->     ets:insert(DB, {{Owner, ObjectID}, TimerPID, Data}),     Data. +add_update_to_cache (DB, Owner, ObjectID, Data) -> +   {ok, TimerPID} = gen_server:start(?MODULE, {DB, {Owner, ObjectID}}, []), +   ets:insert(DB, {{Owner, ObjectID}, TimerPID, Data}). +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -87,6 +92,17 @@ fetch (DB, Owner, ObjectID) ->           Data     end. +update (DB, Owner, ObjectID, Data) -> +   io:format("~nUpdating cache: ~p.~n", [{DB, {Owner, ObjectID}}]), +   case ets:lookup(DB, {Owner, ObjectID}) of +      [] -> ok; + +      [{_OwnerID, TimerPID, _Data}] -> +         gen_server:stop(TimerPID), +   end, +   add_update_to_cache(DB, Owner, ObjectID); + +  invalidate (DB, Owner, ObjectID) ->     case ets:lookup(DB, {Owner, ObjectID}) of        [] -> | 


