optimistic writeback and pessimistic read

This commit is contained in:
2023-11-03 00:56:56 -07:00
parent 0fc1bf396d
commit 610b979966
3 changed files with 139 additions and 93 deletions

View File

@@ -9,6 +9,7 @@ func (c *ConfigManager) SetBool(key string, value bool) {
defer c.mutex.Unlock()
lower := strings.ToLower(key)
c.mapConfig[lower] = ConfigMap{Key: key, Value: value}
c.combinedConfig[lower] = ConfigMap{Key: key, Value: value}
}
func (c *ConfigManager) SetString(key string, value string) {
@@ -16,6 +17,7 @@ func (c *ConfigManager) SetString(key string, value string) {
defer c.mutex.Unlock()
lower := strings.ToLower(key)
c.mapConfig[lower] = ConfigMap{Key: key, Value: value}
c.combinedConfig[lower] = ConfigMap{Key: key, Value: value}
}
func (c *ConfigManager) Set(key string, value any) {
@@ -23,6 +25,7 @@ func (c *ConfigManager) Set(key string, value any) {
defer c.mutex.Unlock()
lower := strings.ToLower(key)
c.mapConfig[lower] = ConfigMap{Key: key, Value: value}
c.combinedConfig[lower] = ConfigMap{Key: key, Value: value}
}
func (c *ConfigManager) SetDefault(key string, value any) {
@@ -30,4 +33,10 @@ func (c *ConfigManager) SetDefault(key string, value any) {
defer c.mutex.Unlock()
lower := strings.ToLower(key)
c.defaultConfig[lower] = ConfigMap{Key: key, Value: value}
if _, ok := c.mapConfig[lower]; !ok {
if envVal, ok := c.envConfig[lower]; !ok {
c.mapConfig[lower] = envVal
c.combinedConfig[lower] = envVal
}
}
}