@@ -34,6 +34,11 @@ type Config struct {
34
34
DryRun bool
35
35
// PrepareStmt executes the given query in cached statement
36
36
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
+
37
42
// DisableAutomaticPing
38
43
DisableAutomaticPing bool
39
44
// DisableForeignKeyConstraintWhenMigrating
@@ -105,6 +110,8 @@ type DB struct {
105
110
type Session struct {
106
111
DryRun bool
107
112
PrepareStmt bool
113
+ PrepareStmtMaxSize int
114
+ PrepareStmtTTL time.Duration
108
115
NewDB bool
109
116
Initialized bool
110
117
SkipHooks bool
@@ -197,7 +204,7 @@ func Open(dialector Dialector, opts ...Option) (db *DB, err error) {
197
204
}
198
205
199
206
if config .PrepareStmt {
200
- preparedStmt := NewPreparedStmtDB (db .ConnPool )
207
+ preparedStmt := NewPreparedStmtDB (db .ConnPool , config . PrepareStmtMaxSize , config . PrepareStmtTTL )
201
208
db .cacheStore .Store (preparedStmtDBKey , preparedStmt )
202
209
db .ConnPool = preparedStmt
203
210
}
@@ -268,7 +275,7 @@ func (db *DB) Session(config *Session) *DB {
268
275
if v , ok := db .cacheStore .Load (preparedStmtDBKey ); ok {
269
276
preparedStmt = v .(* PreparedStmtDB )
270
277
} else {
271
- preparedStmt = NewPreparedStmtDB (db .ConnPool )
278
+ preparedStmt = NewPreparedStmtDB (db .ConnPool , config . PrepareStmtMaxSize , config . PrepareStmtTTL )
272
279
db .cacheStore .Store (preparedStmtDBKey , preparedStmt )
273
280
}
274
281
0 commit comments