支持lru缓存
This commit is contained in:
parent
36126b8856
commit
057f5fdcd6
@ -37,7 +37,8 @@ func NewPreparedStmtDB(connPool ConnPool, prepareStmtLruConfig *PrepareStmtLruCo
|
|||||||
lru.NewLru(prepareStmtLruConfig.Size, prepareStmtLruConfig.TTL)
|
lru.NewLru(prepareStmtLruConfig.Size, prepareStmtLruConfig.TTL)
|
||||||
stmts = lru
|
stmts = lru
|
||||||
} else {
|
} else {
|
||||||
stmts = &DefaultStmtStore{}
|
defaultStmtStore := &DefaultStmtStore{}
|
||||||
|
stmts = defaultStmtStore.init()
|
||||||
}
|
}
|
||||||
return stmts
|
return stmts
|
||||||
}(),
|
}(),
|
||||||
@ -87,7 +88,9 @@ func (sdb *PreparedStmtDB) Reset() {
|
|||||||
}
|
}
|
||||||
}(stmt)
|
}(stmt)
|
||||||
}
|
}
|
||||||
sdb.Stmts = &DefaultStmtStore{}
|
defaultStmt := &DefaultStmtStore{}
|
||||||
|
defaultStmt.init()
|
||||||
|
sdb.Stmts = defaultStmt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *PreparedStmtDB) prepare(ctx context.Context, conn ConnPool, isTransaction bool, query string) (Stmt, error) {
|
func (db *PreparedStmtDB) prepare(ctx context.Context, conn ConnPool, isTransaction bool, query string) (Stmt, error) {
|
||||||
@ -302,6 +305,11 @@ type DefaultStmtStore struct {
|
|||||||
defaultStmt map[string]*Stmt
|
defaultStmt map[string]*Stmt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DefaultStmtStore) init() *DefaultStmtStore {
|
||||||
|
s.defaultStmt = make(map[string]*Stmt)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DefaultStmtStore) AllMap() map[string]*Stmt {
|
func (s *DefaultStmtStore) AllMap() map[string]*Stmt {
|
||||||
return s.defaultStmt
|
return s.defaultStmt
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user