Abstract the cleanup logic and add helper for cache valid.

This commit is contained in:
2025-02-24 12:02:12 +00:00
parent 2743b0e024
commit 0f8b7f7ab1
3 changed files with 25 additions and 23 deletions
+1 -10
View File
@@ -178,16 +178,7 @@ func (c *Cache) removeItem(key string) {
// startAutoCleanup initiates a goroutine that periodically cleans up expired cache items.
func (c *Cache) startAutoCleanup() {
ticker := time.NewTicker(c.autoCleanupInterval)
for {
select {
case <-ticker.C:
c.Cleanup()
case <-c.stopCleanup:
ticker.Stop()
return
}
}
autoCleanupRoutine(c.autoCleanupInterval, c.stopCleanup, c.Cleanup)
}
// Close terminates the auto cleanup goroutine.