Skip to content

Commit

Permalink
rename prestconf enablecache to pgcache
Browse files Browse the repository at this point in the history
this variable is used to cache sql queries, not query results

Signed-off-by: Avelino <avelinorun@gmail.com>
  • Loading branch information
avelino committed Dec 23, 2021
1 parent afe18fa commit d855ece
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions adapters/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Stmt struct {

// Prepare statement
func (s *Stmt) Prepare(db *sqlx.DB, tx *sql.Tx, SQL string) (statement *sql.Stmt, err error) {
if config.PrestConf.EnableCache && (tx == nil) {
if config.PrestConf.PGCache && (tx == nil) {
var exists bool
s.Mtx.Lock()
statement, exists = s.PrepareMap[SQL]
Expand All @@ -76,7 +76,7 @@ func (s *Stmt) Prepare(db *sqlx.DB, tx *sql.Tx, SQL string) (statement *sql.Stmt
if err != nil {
return
}
if config.PrestConf.EnableCache && (tx == nil) {
if config.PrestConf.PGCache && (tx == nil) {
s.Mtx.Lock()
s.PrepareMap[SQL] = statement
s.Mtx.Unlock()
Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Prest struct {
PGMaxIdleConn int
PGMAxOpenConn int
PGConnTimeout int
PGCache bool
JWTKey string
JWTAlgo string
JWTWhiteList []string
Expand All @@ -65,7 +66,6 @@ type Prest struct {
Adapter adapters.Adapter
EnableDefaultJWT bool
SingleDB bool
EnableCache bool
HTTPSMode bool
HTTPSCert string
HTTPSKey string
Expand Down Expand Up @@ -107,12 +107,12 @@ func viperCfg() {
viper.SetDefault("pg.maxopenconn", 10)
viper.SetDefault("pg.conntimeout", 10)
viper.SetDefault("pg.single", true)
viper.SetDefault("pg.cache", true)
viper.SetDefault("debug", false)
viper.SetDefault("jwt.default", true)
viper.SetDefault("jwt.algo", "HS256")
viper.SetDefault("jwt.whitelist", []string{"/auth"})
viper.SetDefault("cors.allowheaders", []string{"*"})
viper.SetDefault("cache.enable", true)
viper.SetDefault("context", "/")
viper.SetDefault("https.mode", false)
viper.SetDefault("https.cert", "/etc/certs/cert.crt")
Expand Down Expand Up @@ -180,6 +180,7 @@ func Parse(cfg *Prest) (err error) {
cfg.PGMaxIdleConn = viper.GetInt("pg.maxidleconn")
cfg.PGMAxOpenConn = viper.GetInt("pg.maxopenconn")
cfg.PGConnTimeout = viper.GetInt("pg.conntimeout")
cfg.PGCache = viper.GetBool("pg.cache")
cfg.SingleDB = viper.GetBool("pg.single")
cfg.JWTKey = viper.GetString("jwt.key")
cfg.JWTAlgo = viper.GetString("jwt.algo")
Expand All @@ -192,7 +193,6 @@ func Parse(cfg *Prest) (err error) {
cfg.CORSAllowHeaders = viper.GetStringSlice("cors.allowheaders")
cfg.Debug = viper.GetBool("debug")
cfg.EnableDefaultJWT = viper.GetBool("jwt.default")
cfg.EnableCache = viper.GetBool("cache.enable")
cfg.ContextPath = viper.GetString("context")
cfg.HTTPSMode = viper.GetBool("https.mode")
cfg.HTTPSCert = viper.GetString("https.cert")
Expand Down

0 comments on commit d855ece

Please sign in to comment.