diff options
author | Marc Pervaz Boocha <marcpervaz@qburst.com> | 2025-02-21 18:24:35 +0530 |
---|---|---|
committer | Marc Pervaz Boocha <marcpervaz@qburst.com> | 2025-02-21 18:24:35 +0530 |
commit | a470aa89cbdabba813636b8a29be8ae3836c03a0 (patch) | |
tree | 2551bebaff980cc93bf8fcf60dd8ff50bd7efc48 /utils.go | |
parent | Add Tests and benchmarks (diff) | |
download | cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar.gz cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar.bz2 cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar.lz cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar.xz cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar.zst cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.zip |
Added LTR Eviction
Diffstat (limited to 'utils.go')
-rw-r--r-- | utils.go | 50 |
1 files changed, 0 insertions, 50 deletions
@@ -2,58 +2,8 @@ package cache import ( "hash/fnv" - "math" - "time" ) -// pauseTimer is a struct that wraps a time.Ticker and provides additional functionality -// to pause and resume the ticker. -// If the duration is 0, the timer is created in a stopped state. -type pauseTimer struct { - *time.Ticker - duration time.Duration -} - -// newPauseTimer creates a new pauseTimer with the specified duration. -func newPauseTimer(d time.Duration) *pauseTimer { - ret := &pauseTimer{duration: d} - if d != 0 { - ret.Ticker = time.NewTicker(d) - } else { - ret.Ticker = time.NewTicker(math.MaxInt64) - ret.Reset(0) - } - return ret -} - -// newPauseTimerStopped creates a new pauseTimer with the specified duration and stops it immediately. -func newPauseTimerStopped(d time.Duration) *pauseTimer { - ret := newPauseTimer(d) - ret.Stop() - return ret -} - -// Reset sets the timer to the specified duration and starts it. -// If the duration is 0, the timer is stopped. -func (t *pauseTimer) Reset(d time.Duration) { - t.duration = d - if t.duration == 0 { - t.Stop() - } else { - t.Ticker.Reset(d) - } -} - -// Resume resumes the timer with its last set duration. -func (t *pauseTimer) Resume() { - t.Reset(t.GetDuration()) -} - -// GetDuration returns the current duration of the timer. -func (t *pauseTimer) GetDuration() time.Duration { - return t.duration -} - // zero returns the zero value for the specified type. func zero[T any]() T { var ret T |