Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question on loading new/stale property with get_env #113

Open
reverendpaco opened this issue Jul 4, 2016 · 1 comment
Open

Question on loading new/stale property with get_env #113

reverendpaco opened this issue Jul 4, 2016 · 1 comment

Comments

@reverendpaco
Copy link

I am using get_env() to read a config file (i.e. [app_env]).

If I change the configuration file, is there an API I can use to tell gproc to reload this (or all) properties? It's not exactly clear that there is a way, and I'm digging into the code right now to figure it out.

thanks

@uwiger
Copy link
Owner

uwiger commented Jul 4, 2016

Well, if you use gproc:get_env() consistently, gproc will always go back to the source. If you use gproc:get_set_env(), gproc will cache the result (even undefined if the value isn't found).

Once you have cached the value, gproc will read the cache every time. There is no API function for clearing the cache, but you could do:

Eshell V8.0  (abort with ^G)
1> application:ensure_all_started(gproc).
{ok,[gproc]}
2> application:set_env(gproc,a,5).   % load conf
ok
3> gproc:get_set_env(l,gproc,a).     % cache value
5
4> {gproc,L} = gproc:info(self(),{gproc,{p,l,{gproc_env,'_','_'}}}).
{gproc,[{{p,l,{gproc_env,gproc,a}},5}]}
5> [gproc:unreg(K) || {K,V} <- L].    % clear cache
[true]
6> gproc:info(self(),{gproc,{p,l,{gproc_env,'_','_'}}}).
{gproc,[]}
7> application:set_env(gproc,a,7).      % reload conf
ok
8> gproc:get_set_env(l,gproc,a).
7
9> gproc:info(self(),{gproc,{p,l,{gproc_env,'_','_'}}}).
{gproc,[{{p,l,{gproc_env,gproc,a}},7}]}

The pattern gproc:info(Pid, {gproc, Pattern}) is not documented. This is an oversight. It should be the most scalable[1] way to fetch your own cached values (remember, you can't clear the cache of any other process).

[1] I.e. it uses the reverse mapping for the Pid. The QLC table generator could theoretically do that too, if the pid pattern is bound, but it currently doesn't. Anyone who feels strongly about this is welcome to try for a PR. Using gproc:select() with wildcards in the gproc_env tuple pattern, the operation will scan the cached values of all processes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants