Source File
lru.go
Belonging Package
github.com/jackc/pgconn/stmtcache
:= .conn.TxStatus()
if ( == 'I' || == 'T') && len(.stmtsToClear) > 0 {
for , := range .stmtsToClear {
:= .clearStmt(, )
if != nil {
return nil,
}
}
}
if , := .m[]; {
.l.MoveToFront()
return .Value.(*pgconn.StatementDescription), nil
}
if .l.Len() == .cap {
:= .removeOldest()
if != nil {
return nil,
}
}
, := .prepare(, )
if != nil {
return nil,
}
:= .l.PushFront()
.m[] =
return , nil
}
func ( *LRU) ( context.Context) error {
for .l.Len() > 0 {
:= .removeOldest()
if != nil {
return
}
}
return nil
}
func ( *LRU) ( string, error) {
, := .(*pgconn.PgError)
if ! {
return
}
:= .Severity == "ERROR" &&
.Code == "0A000" &&
.Message == "cached plan must not change result type"
if {
.stmtsToClear = append(.stmtsToClear, )
}
}
func ( *LRU) ( context.Context, string) error {
, := .m[]
func ( *LRU) () int {
return .mode
}
func ( *LRU) ( context.Context, string) (*pgconn.StatementDescription, error) {
var string
if .mode == ModePrepare {
= fmt.Sprintf("%s_%d", .psNamePrefix, .prepareCount)
.prepareCount += 1
}
return .conn.Prepare(, , , nil)
}
func ( *LRU) ( context.Context) error {
:= .l.Back()
.l.Remove()
:= .Value.(*pgconn.StatementDescription)
delete(.m, .SQL)
if .mode == ModePrepare {
return .conn.Exec(, fmt.Sprintf("deallocate %s", .Name)).Close()
}
return nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |