-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleaner.go
74 lines (65 loc) · 1.09 KB
/
cleaner.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package pot
import (
"time"
"github.com/swxctx/pot/plog"
)
// cleaner job for clean cache
type cleaner struct {
// run interval
Interval time.Duration
// stop flag
stop chan bool
}
/*
Run
@Desc: run value clean routine
@receiver: cl
@param: c
*/
func (cl *cleaner) run(c *cache) {
plog.Infof("run cleaner job...")
ticker := time.NewTicker(cl.Interval)
for {
select {
case <-ticker.C:
c.expiredRoutine()
case <-cl.stop:
ticker.Stop()
return
}
}
}
/*
startCleaner
@Desc: 启动处理器
@receiver: c
*/
func (p *Pot) startCleaner() {
go p.cleaner.run(p.getCache())
}
/*
stopJanitor
@Desc: 停止处理
@receiver: p
*/
func (p *Pot) stopCleaner() {
p.cleaner.stop <- true
}
/*
newCleaner
@Desc: new cleaner
@param: interval
@return: *cleaner
*/
func newCleaner(intervalArg time.Duration) *cleaner {
interval := intervalArg
if interval.Seconds() == 0 {
interval = time.Duration(1) * time.Second
}
cleanerVal := &cleaner{
Interval: interval,
stop: make(chan bool),
}
plog.Infof("cleaner init finish, interval second-> %vs", interval.Seconds())
return cleanerVal
}