forked from PolarPanda611/trinity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.go
More file actions
48 lines (40 loc) · 1.15 KB
/
Copy pathcache.go
File metadata and controls
48 lines (40 loc) · 1.15 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
package trinity
import (
"time"
"github.com/bluele/gcache"
)
func initDefaultCache(cacheAlgorithm string, cacheSize int, timeout int) gcache.Cache {
switch cacheAlgorithm {
case "LFU":
return gcache.New(cacheSize).LFU().Expiration(time.Duration(timeout) * time.Hour).Build()
case "LRU":
return gcache.New(cacheSize).LRU().Expiration(time.Duration(timeout) * time.Hour).Build()
case "ARC":
return gcache.New(cacheSize).ARC().Expiration(time.Duration(timeout) * time.Hour).Build()
default:
return gcache.New(cacheSize).Expiration(time.Duration(timeout) * time.Hour).Build()
}
}
func (t *Trinity) initCache() {
t.cache = initDefaultCache("LRU", t.setting.GetCacheSize(), t.setting.GetCacheTimeout())
}
// CleanCache clean the current cache
func (t *Trinity) CleanCache() {
t.mu.Lock()
t.cache = initDefaultCache("LRU", t.setting.GetCacheSize(), t.setting.GetCacheTimeout())
t.mu.Unlock()
}
// GetCache get vcfg
func (t *Trinity) GetCache() gcache.Cache {
t.mu.RLock()
c := t.cache
t.mu.RUnlock()
return c
}
// SetCache get vcfg
func (t *Trinity) SetCache(cache gcache.Cache) *Trinity {
t.mu.Lock()
t.cache = cache
t.mu.Unlock()
return t
}