-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtag_cache.go
More file actions
74 lines (58 loc) · 1.74 KB
/
Copy pathtag_cache.go
File metadata and controls
74 lines (58 loc) · 1.74 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package tagcache
type TagCache struct {
store CacheStore
tagSet *TagSet
}
var _ Cache = new(TagCache)
func NewTagCache(store CacheStore, names ...string) Cache {
return &TagCache{store: store, tagSet: NewTagSet(store, names)}
}
func (this *TagCache) TaggedItemKey(key string) string {
return EncodeMD5(this.tagSet.GetNamespace() + ":" + key)
}
func (this *TagCache) Set(key, value string, expire int64) error {
return this.store.Set(this.TaggedItemKey(key), value, expire)
}
// func (this *TagCache) MSet(items map[string]string, expire int64) error {
// m := map[string]string{}
// for k, _ := range items {
// m[this.TaggedItemKey(k)] = items[k]
// }
// return this.store.MSet(m, expire)
// }
func (this *TagCache) Get(key string) string {
return this.store.Get(this.TaggedItemKey(key))
}
// func (this *TagCache) MGet(keys []string) []string {
// for i, _ := range keys {
// keys[i] = this.TaggedItemKey(keys[i])
// }
// return this.store.MGet(keys)
// }
// 更新过期时间
func (this *TagCache) Touch(key string, expire int64) error {
return this.store.Touch(this.TaggedItemKey(key), expire)
}
func (this *TagCache) Incr(key string) (int64, error) {
return this.store.Incr(this.TaggedItemKey(key))
}
func (this *TagCache) Decr(key string) (int64, error) {
return this.store.Decr(this.TaggedItemKey(key))
}
func (this *TagCache) Delete(key string) error {
return this.store.Delete(this.TaggedItemKey(key))
}
func (this *TagCache) Flush() error {
return this.tagSet.Reset()
}
// add Tags
func (this *TagCache) Tags(tags []string) Cache {
this.tagSet.AddNames(tags)
return this
}
func (this *TagCache) StartAndGC(opt Options) error {
return this.store.StartAndGC(opt)
}
func (this *TagCache) Info() string {
return this.store.Info()
}