mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
improve cache feature for package gdb
This commit is contained in:
@ -34,9 +34,10 @@ type CacheOption struct {
|
||||
Force bool
|
||||
}
|
||||
|
||||
// selectCacheItem is the cache item for SELECT statement result.
|
||||
type selectCacheItem struct {
|
||||
Result Result
|
||||
FirstResultColumn string
|
||||
Result Result // Sql result of SELECT statement.
|
||||
FirstResultColumn string // The first column name of result, for Value/Count functions.
|
||||
}
|
||||
|
||||
// Cache sets the cache feature for the model. It caches the result of the sql, which means
|
||||
@ -128,7 +129,6 @@ func (m *Model) makeSelectCacheKey(sql string, args ...interface{}) string {
|
||||
if len(cacheKey) == 0 {
|
||||
cacheKey = fmt.Sprintf(
|
||||
`GCache@Schema(%s):%s`,
|
||||
m.db.GetSchema(),
|
||||
gmd5.MustEncryptString(sql+", @PARAMS:"+gconv.String(args)),
|
||||
)
|
||||
}
|
||||
|
||||
@ -176,7 +176,10 @@ func (m *Model) Value(fieldsAndWhere ...interface{}) (Value, error) {
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
return nil, gerror.NewCode(gcode.CodeInternalError, `query value error`)
|
||||
return nil, gerror.NewCode(
|
||||
gcode.CodeInternalError,
|
||||
`query value error: the internal context data is missing. there's' internal issue should be fixed'`,
|
||||
)
|
||||
}
|
||||
|
||||
// Array queries and returns data values as slice from database.
|
||||
@ -390,7 +393,10 @@ func (m *Model) Count(where ...interface{}) (int, error) {
|
||||
return v.Int(), nil
|
||||
}
|
||||
}
|
||||
return 0, gerror.NewCode(gcode.CodeInternalError, `query count error`)
|
||||
return 0, gerror.NewCode(
|
||||
gcode.CodeInternalError,
|
||||
`query count error: the internal context data is missing. there's' internal issue should be fixed'`,
|
||||
)
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user