summaryrefslogtreecommitdiff
path: root/system/db/config.go
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-04-17 18:19:19 -0700
committerSteve Manuel <nilslice@gmail.com>2017-04-17 18:19:19 -0700
commitdd2cdd3bd5b6f2c25120b3e511fea08432fd9805 (patch)
treef69dd75ae76a3201a4651a9d1b843eee917598b1 /system/db/config.go
parent39a57b403570d8c845a967e66d91b9011e8976ba (diff)
adding mutex to protect configCache map, fixes race condition
Diffstat (limited to 'system/db/config.go')
-rw-r--r--system/db/config.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/system/db/config.go b/system/db/config.go
index 6a409c2..5bb010a 100644
--- a/system/db/config.go
+++ b/system/db/config.go
@@ -6,6 +6,7 @@ import (
"fmt"
"net/url"
"strings"
+ "sync"
"github.com/ponzu-cms/ponzu/system/admin/config"
@@ -18,6 +19,7 @@ const (
DefaultMaxAge = int64(60 * 60 * 24 * 30)
)
+var mu = &sync.Mutex{}
var configCache map[string]interface{}
func init() {
@@ -115,7 +117,9 @@ func SetConfig(data url.Values) error {
return err
}
+ mu.Lock()
configCache = kv
+ mu.Unlock()
return nil
}
@@ -215,7 +219,11 @@ func PutConfig(key string, value interface{}) error {
// ConfigCache is a in-memory cache of the Configs for quicker lookups
// 'key' is the JSON tag associated with the config field
func ConfigCache(key string) interface{} {
- return configCache[key]
+ mu.Lock()
+ val := configCache[key]
+ mu.Unlock()
+
+ return val
}
// LoadCacheConfig loads the config into a cache to be accessed by ConfigCache()
@@ -239,7 +247,9 @@ func LoadCacheConfig() error {
return err
}
+ mu.Lock()
configCache = kv
+ mu.Unlock()
return nil
}