In my config.exs file, I have
config :my_app,
foobar: [%{foo: "bar", keywords: ["hello", "world!"]},
%{foo: "xyz", keywords: ["bloop"]}]
this list is retrieved in the code
Application.get_env(:my_app, :foobar)
But if I were to update this foobar config, the changes will not take into effect until I restart the application.
Alternatively, is there a better way to go about with this? My original solution parsed a list of lists from a file. It worked great whenever I modified the file, but now I want to work with a list of maps.
I am not aware of any solution that would allow to dynamically reload configuration. It would be hard as configuration flags can influence compilation, for example:
defmodule Foo do
@foo Application.get(:foo, __MODULE__)
def foo, do: @foo
end
In this snippet @foo
will be computed during compilation.
However you can change configuration using Application.put_env/3
, but it will affect only runtime fragments.
How do you use the configuration in the code? The change should take place when you use Application.get_env/2 to retrieve the value. Or is it because the config file needs to be recompiled?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.