Packages
launchdarkly_server_sdk
1.6.0
3.11.0
3.10.1
3.9.0
3.8.1
3.8.0
3.7.2
3.7.1
3.7.0
3.6.0
3.5.0
3.4.0
3.3.1
3.3.0
3.2.0
3.1.0
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.1.2
2.1.1
2.1.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.6.0
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.0
1.1.3
1.1.2
1.1.1
retired
1.1.0
retired
1.0.1
retired
1.0.0
retired
1.0.0-beta4
retired
1.0.0-beta3
retired
1.0.0-beta2
retired
LaunchDarkly SDK for Erlang
Current section
Files
Jump to
Current section
Files
src/ldclient_user_cache.erl
%%-------------------------------------------------------------------
%% @doc User LRU cache
%% @private
%% @end
%%-------------------------------------------------------------------
-module(ldclient_user_cache).
%% API
-export([get_local_reg_name/1]).
-export([notice_user/2]).
%%===================================================================
%% API
%%===================================================================
-spec get_local_reg_name(Tag :: atom()) -> atom().
get_local_reg_name(Tag) ->
list_to_atom("ldclient_user_cache_" ++ atom_to_list(Tag)).
%% @doc Add to the set of the users we've noticed, and return true if the user
%% was already known to us.
%%
%% @end
-spec notice_user(Tag :: atom(), User :: ldclient_user:user()) -> boolean().
notice_user(_Tag, #{key := <<>>}) ->
% Empty user key always returns true so it's not indexed
true;
notice_user(_Tag, #{key := null}) ->
% Null user key always returns true so it's not indexed
true;
notice_user(Tag, #{key := UserKey}) ->
CacheServer = get_local_reg_name(Tag),
{Exists, _} = lru:contains_or_add(whereis(CacheServer), UserKey, UserKey),
Exists;
notice_user(_Tag, _User) ->
% No user key always returns true so it's not indexed
true.