forked from alice-lg/birdwatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhousekeeping.go
42 lines (34 loc) · 931 Bytes
/
housekeeping.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
package main
import (
"log"
"runtime/debug"
"time"
"github.com/alice-lg/birdwatcher/bird"
)
type HousekeepingConfig struct {
Interval int `toml:"interval"`
ForceReleaseMemory bool `toml:"force_release_memory"`
}
// This is used to run regular housekeeping tasks, currently expiring old
// Cache entries to release memory
func Housekeeping(config HousekeepingConfig, expireCaches bool) {
for {
if config.Interval > 0 {
time.Sleep(time.Duration(config.Interval) * time.Minute)
} else {
time.Sleep(5 * time.Minute)
}
log.Println("Housekeeping started")
if (bird.ClientConf.CacheTtl > 0) && expireCaches {
// Expire the caches
log.Println("Expiring MemoryCache")
count := bird.ExpireCache()
log.Println("Expired", count, "entries (MemoryCache)")
}
if config.ForceReleaseMemory {
// Trigger a GC and SCVG run
log.Println("Freeing memory")
debug.FreeOSMemory()
}
}
}