@@ -34,6 +34,11 @@ type Config struct {
3434 DryRun bool
3535 // PrepareStmt executes the given query in cached statement
3636 PrepareStmt bool
37+ // PrepareStmt cache support LRU expired,
38+ // default maxsize=int64 Max value and ttl=1h
39+ PrepareStmtMaxSize int
40+ PrepareStmtTTL time.Duration
41+
3742 // DisableAutomaticPing
3843 DisableAutomaticPing bool
3944 // DisableForeignKeyConstraintWhenMigrating
@@ -105,6 +110,8 @@ type DB struct {
105110type Session struct {
106111 DryRun bool
107112 PrepareStmt bool
113+ PrepareStmtMaxSize int
114+ PrepareStmtTTL time.Duration
108115 NewDB bool
109116 Initialized bool
110117 SkipHooks bool
@@ -197,7 +204,7 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) {
197204 }
198205
199206 if config .PrepareStmt {
200- preparedStmt := NewPreparedStmtDB (db .ConnPool )
207+ preparedStmt := NewPreparedStmtDB (db .ConnPool , config . PrepareStmtMaxSize , config . PrepareStmtTTL )
201208 db .cacheStore .Store (preparedStmtDBKey , preparedStmt )
202209 db .ConnPool = preparedStmt
203210 }
@@ -268,7 +275,7 @@ func (db *DB) Session(config *Session) *DB {
268275 if v , ok := db .cacheStore .Load (preparedStmtDBKey ); ok {
269276 preparedStmt = v .(* PreparedStmtDB )
270277 } else {
271- preparedStmt = NewPreparedStmtDB (db .ConnPool )
278+ preparedStmt = NewPreparedStmtDB (db .ConnPool , config . PrepareStmtMaxSize , config . PrepareStmtTTL )
272279 db .cacheStore .Store (preparedStmtDBKey , preparedStmt )
273280 }
274281
0 commit comments