Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Config struct {
DryRun bool
// PrepareStmt executes the given query in cached statement
PrepareStmt bool
// PrepareStmt cache support LRU expired
PrepareStmtLruConfig *PrepareStmtLruConfig
// DisableAutomaticPing
DisableAutomaticPing bool
// DisableForeignKeyConstraintWhenMigrating
Expand Down Expand Up @@ -65,6 +67,11 @@ type Config struct {
callbacks *callbacks
cacheStore *sync.Map
}
type PrepareStmtLruConfig struct {
Size int
TTL time.Duration
Open bool
}

// Apply update config to new config
func (c *Config) Apply(config *Config) error {
Expand Down Expand Up @@ -197,7 +204,7 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) {
}

if config.PrepareStmt {
preparedStmt := NewPreparedStmtDB(db.ConnPool)
preparedStmt := NewPreparedStmtDB(db.ConnPool, config.PrepareStmtLruConfig)
db.cacheStore.Store(preparedStmtDBKey, preparedStmt)
db.ConnPool = preparedStmt
}
Expand Down Expand Up @@ -268,7 +275,7 @@ func (db *DB) Session(config *Session) *DB {
if v, ok := db.cacheStore.Load(preparedStmtDBKey); ok {
preparedStmt = v.(*PreparedStmtDB)
} else {
preparedStmt = NewPreparedStmtDB(db.ConnPool)
preparedStmt = NewPreparedStmtDB(db.ConnPool, db.Config.PrepareStmtLruConfig)
db.cacheStore.Store(preparedStmtDBKey, preparedStmt)
}

Expand Down
Loading