feat: add simple cache, due to jackett poor performance

This commit is contained in:
Simon Ding
2024-08-07 10:42:12 +08:00
parent 466596345d
commit bd385d4f85
3 changed files with 55 additions and 17 deletions

31
pkg/torznab/cache.go Normal file
View File

@@ -0,0 +1,31 @@
package torznab
import (
"polaris/log"
"polaris/pkg/utils"
"github.com/robfig/cron"
"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()
}