支持lru缓存
This commit is contained in:
parent
057f5fdcd6
commit
565375dfb7
@ -24,25 +24,26 @@ type PreparedStmtDB struct {
|
|||||||
ConnPool
|
ConnPool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newPrepareStmtCache(prepareStmtLruConfig *PrepareStmtLruConfig) *StmtStore {
|
||||||
|
var stmts StmtStore
|
||||||
|
if prepareStmtLruConfig != nil && prepareStmtLruConfig.Open {
|
||||||
|
if prepareStmtLruConfig.Size <= 0 {
|
||||||
|
panic("LRU prepareStmtLruConfig.Size must > 0")
|
||||||
|
}
|
||||||
|
lru := &LruStmtStore{}
|
||||||
|
lru.NewLru(prepareStmtLruConfig.Size, prepareStmtLruConfig.TTL)
|
||||||
|
stmts = lru
|
||||||
|
} else {
|
||||||
|
defaultStmtStore := &DefaultStmtStore{}
|
||||||
|
stmts = defaultStmtStore.init()
|
||||||
|
}
|
||||||
|
return &stmts
|
||||||
|
}
|
||||||
func NewPreparedStmtDB(connPool ConnPool, prepareStmtLruConfig *PrepareStmtLruConfig) *PreparedStmtDB {
|
func NewPreparedStmtDB(connPool ConnPool, prepareStmtLruConfig *PrepareStmtLruConfig) *PreparedStmtDB {
|
||||||
return &PreparedStmtDB{
|
return &PreparedStmtDB{
|
||||||
ConnPool: connPool,
|
ConnPool: connPool,
|
||||||
Stmts: func() StmtStore {
|
Stmts: *newPrepareStmtCache(prepareStmtLruConfig),
|
||||||
var stmts StmtStore
|
Mux: &sync.RWMutex{},
|
||||||
if prepareStmtLruConfig != nil && prepareStmtLruConfig.Open {
|
|
||||||
if prepareStmtLruConfig.Size <= 0 {
|
|
||||||
panic("LRU prepareStmtLruConfig.Size must > 0")
|
|
||||||
}
|
|
||||||
lru := &LruStmtStore{}
|
|
||||||
lru.NewLru(prepareStmtLruConfig.Size, prepareStmtLruConfig.TTL)
|
|
||||||
stmts = lru
|
|
||||||
} else {
|
|
||||||
defaultStmtStore := &DefaultStmtStore{}
|
|
||||||
stmts = defaultStmtStore.init()
|
|
||||||
}
|
|
||||||
return stmts
|
|
||||||
}(),
|
|
||||||
Mux: &sync.RWMutex{},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user