Merge pull request #15949 from stonezdj/21nov4_cache_properties

Enable db config cache explicitly
This commit is contained in:
stonezdj(Daojun Zhang) 2021-11-16 14:39:10 +08:00 committed by GitHub
commit 060341ba4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -54,6 +54,7 @@ import (
"github.com/goharbor/harbor/src/lib/orm"
tracelib "github.com/goharbor/harbor/src/lib/trace"
"github.com/goharbor/harbor/src/migration"
dbCfg "github.com/goharbor/harbor/src/pkg/config/db"
_ "github.com/goharbor/harbor/src/pkg/config/inmemory"
"github.com/goharbor/harbor/src/pkg/notification"
_ "github.com/goharbor/harbor/src/pkg/notifier/topic"
@ -176,6 +177,9 @@ func main() {
if err := cache.Initialize(u.Scheme, redisURL); err != nil {
log.Fatalf("failed to initialize cache: %v", err)
}
// when config/db init function is called, the cache is not ready,
// enable config cache explicitly when the cache is ready
dbCfg.EnableConfigCache()
}
beego.AddTemplateExt("htm")

View File

@ -44,3 +44,12 @@ func NewDBCfgManager() *config.CfgManager {
manager.LoadSystemConfigFromEnv()
return manager
}
// EnableConfigCache ...
func EnableConfigCache() {
if cache.Default() == nil {
log.Error("failed to enable config cache, cache is not ready.")
return
}
libCfg.Register(common.DBCfgManager, NewDBCfgManager())
}