fix (config): synchronise cache writes (#237)

Cache writes used in Config.Get() method wasn't synchronized.
Use sync.Mutex to make it thread-save.
This commit is contained in:
brxie 2020-03-02 22:47:59 +01:00 committed by GitHub
parent f3c4bdb8a8
commit c117c99401
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -414,6 +414,7 @@ func (this *Configuration) Get(key string) *Configuration {
}
// increase speed (x4 with our bench) by using a cache
this.mu.Lock()
tmp := this.cache.Get(key)
if tmp == nil {
this.currentElement = traverse(&this.form, strings.Split(key, "."))
@ -421,6 +422,7 @@ func (this *Configuration) Get(key string) *Configuration {
} else {
this.currentElement = tmp.(*FormElement)
}
this.mu.Unlock()
return this
}