summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-cache/v2/scheduler.go
blob: bc1d8074a3c191f75b7ef373b2012cca7ca538e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package cache

import (
	"time"

	"codeberg.org/gruf/go-sched"
)

// scheduler is the global cache runtime scheduler
// for handling regular cache evictions.
var scheduler = sched.NewScheduler(5)

// schedule will given sweep  routine to the global scheduler, and start global scheduler.
func schedule(sweep func(time.Time), freq time.Duration) func() {
	go scheduler.Start() // does nothing if already running
	return scheduler.Schedule(sched.NewJob(sweep).Every(freq))
}