Replies: 3 comments 8 replies
-
|
I am wondering, if the low-level API is split out into a behaviour so that we are allowed to implement whatever backend we want for configuration retrieval (ENV vars vs Hashicorp Vault vs AWS Secret manager vs ...), can this library provide an interface to a cache between all backends or would it be up to each individual backend to implement a cache? Would we want to provide a way for an entry to expire and automatically retrieve new values, or would the lib just retrieve new values when the application calls for configuration again? |
Beta Was this translation helpful? Give feedback.
-
|
I think the proposed solution makes sense here. I believe we should be able to get started working through it. |
Beta Was this translation helpful? Give feedback.
-
|
Something I came across when working on this. As things are currently implemented, you do not need to call the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
While I never bothered to measure the performance of the provider code, I'm aware of the two issues that might cause problems in some cases:
MyConfig.some_param()).So far I didn't actually experience any problems with this in practice, primarily because I only had to deal with a relatively small number of params, and because these params were only read during the app startup (e.g. to configure endpoint or ecto repo).
However, using provider in a tight loop may significantly affect the code performance.
Proposed solution
Provider.fetch_all) is responsible for implementing its own caching scheme.validate!/0withload!/0. The client code would typically invoke this function in app start callback. The function loads the data, casts and validates it (raising on error), and stores it to an ETS table (owned by the provider app). ETS table is proposed over persistent term to make the cache reload friendly. If the client code wants to refresh the config, they can simply invokeload!/0.{module_name, param_name}as the key for each param.fetch_allfrom the generated code. This one is a bit tricky to implement with the proposed cache, and I currently can't see the use case for it. If people need it in practice, we can add it back.Provider.fetch_oneandProvider.fetch_one!until someone requests this functionality.With the proposed changes the lower-level API would be responsible for fetching the entire config, according to the given schema. The higher-level API (generated module) caches this data, and exposes strongly typed functions for fetching individual values from the cache.
Beta Was this translation helpful? Give feedback.
All reactions