-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_cache.go
60 lines (48 loc) · 1.35 KB
/
base_cache.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
51
52
53
54
55
56
57
58
59
60
package cache
import (
`fmt`
`hash/crc32`
)
type baseCache struct {
options options
}
func (bc *baseCache) getBeanKey(table string, id string) (key string) {
if "" != bc.options.Prefix {
key = fmt.Sprintf("%s:%s:%s:%s", beanPrefix, bc.options.Prefix, table, id)
} else {
key = fmt.Sprintf("%s:%s:%s", beanPrefix, table, id)
}
return
}
func (bc *baseCache) getTableKey(table string) (key string) {
if "" != bc.options.Prefix {
key = fmt.Sprintf("%s:%s:%s", beanPrefix, bc.options.Prefix, table)
} else {
key = fmt.Sprintf("%s:%s", beanPrefix, table)
}
return
}
func (bc *baseCache) getAllTableKey(table string) (key string) {
if "" != bc.options.Prefix {
key = fmt.Sprintf("%s:%s:%s:*", beanPrefix, bc.options.Prefix, table)
} else {
key = fmt.Sprintf("%s:%s:*", beanPrefix, table)
}
return
}
func (bc *baseCache) getSqlKey(table string, sql string) (key string) {
if "" != bc.options.Prefix {
key = fmt.Sprintf("%s:%s:%s:%d", sqlPrefix, bc.options.Prefix, table, crc32.ChecksumIEEE([]byte(sql)))
} else {
key = fmt.Sprintf("%s:%s:%d", sqlPrefix, table, crc32.ChecksumIEEE([]byte(sql)))
}
return
}
func (bc *baseCache) getAllSqlKey(table string) (key string) {
if "" != bc.options.Prefix {
key = fmt.Sprintf("%s:%s:%s:*", sqlPrefix, bc.options.Prefix, table)
} else {
key = fmt.Sprintf("%s:%s:*", sqlPrefix, table)
}
return
}