Packages
launchdarkly_server_sdk
2.1.2
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_context_cache.erl
%%-------------------------------------------------------------------
%% @doc User LRU cache
%% @private
%% @end
%%-------------------------------------------------------------------
-module(ldclient_context_cache).
%% API
-export([get_local_reg_name/1]).
-export([notice_context/2]).
%%===================================================================
%% API
%%===================================================================
-spec get_local_reg_name(Tag :: atom()) -> atom().
get_local_reg_name(Tag) ->
list_to_atom("ldclient_context_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_context(Tag :: atom(), Context :: ldclient_context:context()) -> boolean().
notice_context(Tag, Context) ->
CanonicalKey = ldclient_context:get_canonical_key(Context),
notice_context_canonical_key(Tag, CanonicalKey).
-spec notice_context_canonical_key(Tag :: atom(), CanonicalKey :: binary()) -> boolean().
notice_context_canonical_key(_Tag, <<>>) ->
%% Do not add to the cache. Returning true also means we should not send an index for this invalid user.
true;
notice_context_canonical_key(Tag, CanonicalKey) ->
CacheServer = get_local_reg_name(Tag),
{Exists, _} = lru:contains_or_add(whereis(CacheServer), CanonicalKey, CanonicalKey),
Exists.