feat: change cache implementation

This commit is contained in:
Simon Ding
2024-08-07 11:07:10 +08:00
parent d8d570f1b2
commit f48b3c657e
3 changed files with 63 additions and 28 deletions

View File

@@ -1,31 +1,8 @@
package torznab
import (
"polaris/log"
"polaris/pkg/utils"
"github.com/robfig/cron"
"polaris/pkg/cache"
"time"
)
var cache utils.Map[string, TimedResponse] = utils.Map[string, TimedResponse]{}
type TimedResponse struct {
Response
T time.Time
}
func init() {
cr := cron.New()
cr.AddFunc("@ervery 1m", func() {
cache.Range(func(key string, value TimedResponse) bool {
if time.Since(value.T) > 30*time.Minute {
log.Debugf("delete old cache: %v", key)
cache.Delete(key)
}
return true
})
})
cr.Start()
}
var cc = cache.NewCache[string, Response](time.Minute * 30)