Is it possible to save updated configuration?

Hi, I created a simple application to test how Application methods work:

defmodule MyApp do
        def do_something do
                Application.get_env(:config, :done) |> IO.puts
                Application.put_env(:config, :done, true)

In iex I run this method two times and I got false at first time and true every next runs.
After close iex and start new session results are same.
I want to change this method to always return true in new sessions, so I want to an updated config be saved in same config files. Is it possible in elixir public API?

1 Like

@Eiji I believe what you’re trying to do is not possible, since the configs are read from the config files on startup. Changing them would require writing over the file. I’ve never seen this being done before, at least.

What I recommend is that you have your config getting the values from environment variables and try to change those dynamically (with the System module).

I think this is the case where you want to persist your configuration, so I’d take it out of config file and use a database / ets / dets / redis / whatever suits your application.

Database is not best for store single config.
“ETS allows us to store any Elixir term in an in-memory table.”
“Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and message broker.”
i need a configuration to be saved in file. I think DETS is what I want.
This links should be helpful for other users:
Erlang example
Erlang docs

No this is not what I need. See my response to @yurko.

If you use the Application-module for configuration management, then it will not be possible to save the configuration back into its source, since the configuration is elixir code which is run.

If you really need some configuration that is updatable via your app, you will need to role out your complete own solution which either writes the config into some yaml, json, ini or whatever format or dumps it into some database, table storage or K/V-store.