2022-11-11 11:18:38 +00:00
|
|
|
package ttl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"codeberg.org/gruf/go-sched"
|
|
|
|
)
|
|
|
|
|
2023-01-06 10:16:09 +00:00
|
|
|
// scheduler is the global cache runtime
|
|
|
|
// scheduler for handling cache evictions.
|
2022-11-11 11:18:38 +00:00
|
|
|
var scheduler sched.Scheduler
|
|
|
|
|
|
|
|
// schedule will given sweep routine to the global scheduler, and start global scheduler.
|
|
|
|
func schedule(sweep func(time.Time), freq time.Duration) func() {
|
|
|
|
if !scheduler.Running() {
|
2023-01-06 10:16:09 +00:00
|
|
|
// ensure sched running
|
|
|
|
_ = scheduler.Start(nil)
|
2022-11-11 11:18:38 +00:00
|
|
|
}
|
|
|
|
return scheduler.Schedule(sched.NewJob(sweep).Every(freq))
|
|
|
|
}
|