summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-02-25 23:05:16 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-02-25 23:05:16 +0100 |
commit | 66ec11ce5d2e227846d6e6b2899cda851a70fc04 (patch) | |
tree | 84b586969b622faf6b399bcd9513468ee9fe1900 /src/io | |
parent | d35cd5304d334582d8479062a52a8c7b34f892a1 (diff) |
Adds an update function.
Diffstat (limited to 'src/io')
-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 [] -> |