codeberg.org/gruf/go-cache/v3@v3.5.7/ttl/schedule.go (about)

     1  package ttl
     2  
     3  import (
     4  	"time"
     5  
     6  	"codeberg.org/gruf/go-sched"
     7  )
     8  
     9  // scheduler is the global cache runtime
    10  // scheduler for handling cache evictions.
    11  var scheduler sched.Scheduler
    12  
    13  // schedule will given sweep  routine to the global scheduler, and start global scheduler.
    14  func schedule(sweep func(time.Time), freq time.Duration) func() {
    15  	if !scheduler.Running() {
    16  		// ensure sched running
    17  		_ = scheduler.Start(nil)
    18  	}
    19  	return scheduler.Schedule(sched.NewJob(sweep).Every(freq))
    20  }