I implemented an otp system using gen_server and gen_fsm. There is a configuration file to be read for some values that the software needs in order to run, an example may be:
{values, [value1, value2, value3]}.
I used a macro to extract one of these values
define(VALUES, my_utility:get_conf_value(values)).
The question is the following: since ?VALUES may be called very often, and therefore the configuration file is parsed many times, should I embed ?VALUES inside the state of my gen_server of gen_fsm and extract it with a call any time I need it?
In fact I really appreciated the previous implementation because one could change the behaviour of the software just by changing the values inside the configuration file, without any #state{} change or call.
Which solution do you prefer?
The solution will depend upon your requirements. Performance vs “correctness”.
A possible solution would be to keep the configuration in a process state and re-read it regularly (checking if the file modification time has changed). This might be a good compromise between the two worlds.
Summary:
Requirements not considered: security, stability (corrupt config file?)