Package cache contains caching functions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
482 B

package cache
import "time"
type GC struct {
Interval time.Duration
Cache Cache
stop chan struct{}
}
func NewGC(interval time.Duration, cache Cache) *GC {
return &GC{
Interval: interval,
Cache: cache,
stop: make(chan struct{}),
}
}
func (gc *GC) Run() {
ticker := time.NewTicker(gc.Interval)
for {
select {
case <-ticker.C:
gc.Cache.RunGC()
case <-gc.stop:
ticker.Stop()
return
}
}
}
func (gc *GC) Stop() {
gc.stop <- struct{}{}
}