forked from 8treenet/gcache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcache.go
50 lines (43 loc) · 1.13 KB
/
gcache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package gcache
import (
"github.com/wide288/gcache/internal"
"github.com/wide288/gcache/option"
"gorm.io/gorm"
)
const (
LevelDisable = option.LevelDisable
LevelModel = option.LevelModel
LevelSearch = option.LevelSearch
MinExpires = option.MinExpires
MaxExpires = option.MaxExpires
)
type (
// RedisOption .
RedisOption = option.RedisOption
// ModelOption .
ModelOption = option.ModelOption
// DefaultOption .
DefaultOption = option.DefaultOption
)
// Plugin .
type Plugin interface {
//清库
FlushDB() error
//删除模型缓存
DeleteModel(model interface{}, primarys ...interface{}) error
//删除查询缓存
DeleteSearch(model interface{}) error
//insert select update delete 都会跳过缓存处理
SkipCache() *gorm.DB
//join 和 子查询, 需要传入模型。
CreateRelative(...interface{}) *gorm.DB
SetRelative(*gorm.DB, ...interface{}) *gorm.DB
//tag
CreateTag(...interface{}) *gorm.DB
SetTag(*gorm.DB, ...interface{}) *gorm.DB
Debug()
}
// AttachDB .
func AttachDB(db *gorm.DB, opt *option.DefaultOption, redisOption *option.RedisOption) Plugin {
return internal.InjectGorm(db, opt, redisOption)
}