I use elang ets table as a simple cache. I want to use a process to scan the table and remove expired elements (multiple).
with ets:foldl
expire_table_example() ->
Tab = ets:new(ets_tab, [named_table, set]),
ets:insert(Tab, [{a, 1}, {b, 2}, {c, 3}, {d, 4}, {e, 5},{f,7}]),
Tab1 = ets:foldl(fun({Key, Val}, Acc) ->
if
(Val > 3) -> [{Key, Val} | Acc];
true -> Acc
end
end, Tab, Tab),
io:format("end ~p ~n", [Tab1]).
I got
[{f,7},{e,5},{d,4}|ets_tab] %% the ets_tab is NOT expected.
How Can I fix This?
Any other API's would do this better?
ets_tabin your list is that you're putting it there by usingTabas the second argument toets:foldl/3, which is the initial value of the fold accumulator. You should be using[]for the initial value instead. - Steve Vinoskiets:delete_all_objects/1. - Steve Vinoski