alice-lg/backend/housekeeping.go
Patrick Seeburger bb7c08819a Save memory by periodically expiring cache entries
- Added a method to expire cache entries, based on the ttl.
- Added a housekeeping method that will periodically expire cache
  entries and also maybe configured to force a GC/SCVG run.
2019-03-08 09:58:57 +01:00

35 lines
665 B
Go

package main
import (
"log"
"time"
"runtime/debug"
)
func Housekeeping(config *Config) {
for {
if config.Housekeeping.Interval > 0 {
time.Sleep(time.Duration(config.Housekeeping.Interval) * time.Minute)
} else {
time.Sleep(5 * time.Minute)
}
log.Println("Housekeeping started")
// Expire the caches
log.Println("Expiring caches")
for _, source := range config.Sources {
count := source.getInstance().ExpireCaches()
log.Println("Expired", count, "entries for source", source.Name)
}
if config.Housekeeping.ForceReleaseMemory {
// Trigger a GC and SCVG run
log.Println("Freeing memory")
debug.FreeOSMemory()
}
}
}