This doesn’t work in all situations, but consider that one of the strengths of BEAM is managing state in processes. Why not load the key from the database and keep it in a GenServer’s state, or even just ETS? No need to make the round trip to the DB, and when you write a new key you just kill the old process and let it reload itself from the (now updated) db record.
3 Likes