summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2017-11-16 17:06:17 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2017-11-16 17:06:17 +0100 |
commit | efaf3ee3f4b2478079c7b9dde8f9e879956a460f (patch) | |
tree | 809dba1496ddd1c3058df0722a9fd962fd11f34b /src/timed_cache_object.erl | |
parent | 3cc9f85a8b84f6cb69b828a6510ece7f716a6b28 (diff) |
Starting changes in the structure.
Diffstat (limited to 'src/timed_cache_object.erl')
-rw-r--r-- | src/timed_cache_object.erl | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/src/timed_cache_object.erl b/src/timed_cache_object.erl deleted file mode 100644 index 341d128..0000000 --- a/src/timed_cache_object.erl +++ /dev/null @@ -1,82 +0,0 @@ --module(timed_cache_object). --behavior(gen_server). - -%%%% gen_server exports --export( - [ - init/1, - handle_cast/2, - handle_call/3, %% No reply will ever be given. - terminate/2, - code_change/3, - format_status/2, - handle_info/2 - ] -). - -%%%% actual interface --export( - [ - fetch/2, - invalidate/2 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -add_to_cache (DB, ObjectID) -> - {ok, TimerPID} = gen_server:start(?MODULE, {DB, ObjectID}, []), - {ok, Data} = shim_database:fetch(DB, ObjectID), - ets:insert(DB, {ObjectID, TimerPID, Data}), - Data. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% gen_server - -init ({DB, ObjectID}) -> - {ok, {DB, ObjectID}}. - -handle_call (invalidate, _, State) -> - {stop, normal, State}; -handle_call (ping, _, {DB, ObjectID}) -> - {noreply, {DB, ObjectID}, timed_caches_manager:get_timeout(DB)}. - -handle_cast (invalidate, State) -> - {stop, normal, State}; -handle_cast (ping, {DB, ObjectID}) -> - {noreply, {DB, ObjectID}, timed_caches_manager:get_timeout(DB)}. - -terminate (_, {DB, ObjectID}) -> - ets:delete(DB, ObjectID). - -code_change (_, State, _) -> - {ok, State}. - -format_status (_, [_, State]) -> - [{data, [{"State", State}]}]. - -handle_info(timeout, State) -> - {stop, normal, State}; -handle_info(_, {DB, ObjectID}) -> - {noreply, {DB, ObjectID}, timed_caches_manager:get_timeout(DB)}. - -%%%% interface -fetch (DB, ObjectID) -> - case ets:lookup(DB, ObjectID) of - [] -> add_to_cache(DB, ObjectID); - - [{_, TimerPID, Data}] -> - gen_server:cast(TimerPID, ping), - Data - end. - -invalidate (DB, ObjectID) -> - case ets:lookup(DB, ObjectID) of - [] -> ok; - - [{_, TimerPID, _}] -> - gen_server:stop(TimerPID) - end. |