rogerweb

rogerweb

Is Application.fetch_env expensive?

Hi,

In terms of performance, is it ok to call Application.fetch_env! in a function that is called every time my Phoenix application receives a new websocket connection?

Should I wrap my function in a GenServer just to keep the value in the state? (I don’t think so but just checking)

Is there any “context” that Phoenix might provide that I could use to store this value and somehow would end up being available to me in the socket structure?

The long story is like this: I have this Phoenix application that accepts websocket connections and I am using Joken to verify a token that comes in the connection request. It’s a JWT generated by another system and signed using RS256 so I need to know the public key for verifying it. When the application starts, my runtime.exs reads the public key from an environment variable and stores it as an application configuration. Then, every time a new websocket connection comes in my verify function in my Token module reads the public key using Application.fetch_env! and verifies the token.

Thanks for any guidance.

Marked As Solved

derek-zhou

derek-zhou

Yes. It is cheap enough. also you don’t want to use stale env if those can be updated by user triggered actions within your application.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement