Proper way to storing values for a module?

Hi, I’m making an app using Goth, a Google Cloud OAuth library.

When I use it, it issues an authentication token expired at 1 hour later, so I want to reuse it.

Then, where is the proper place to store it? ETS? Agents? GenServers? Can you give me some decision processes for choosing the storage?

1 Like

In your specific case, Goth already has this built in. In general you just call {:ok %{token: token}} = Goth.fetch(server) every time you need to use the token and if the token is still valid, Goth will just hand you the same token. If the token is invalid, Goth will have refetched it in the background.

Behind the scenes, Goth is using a GenServer + :ets as I recall.

3 Likes