This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
2017-04-05 19:03:44 +02:00
|
|
|
package models
|
|
|
|
|
2017-04-05 20:23:29 +02:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/genofire/hs_master-kss-monolith/lib/worker"
|
|
|
|
)
|
|
|
|
|
|
|
|
var CacheConfig CacheWorkerConfig
|
2017-04-05 19:03:44 +02:00
|
|
|
|
|
|
|
type CacheWorkerConfig struct {
|
|
|
|
Every Duration
|
|
|
|
After Duration
|
|
|
|
}
|
|
|
|
|
2017-04-05 20:23:29 +02:00
|
|
|
func NewCacheWorker() (w *worker.Worker) {
|
|
|
|
return worker.NewWorker(CacheConfig.Every.Duration, func() {
|
|
|
|
before := time.Now().Add(-CacheConfig.After.Duration)
|
2017-04-05 19:03:44 +02:00
|
|
|
// Cache if product exists
|
|
|
|
for index, cache := range productExistCache {
|
2017-04-05 20:23:29 +02:00
|
|
|
if before.After(cache.LastCheck) {
|
2017-04-05 19:03:44 +02:00
|
|
|
delete(productExistCache, index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Cache for permissions
|
|
|
|
for index, cache := range permissionCache {
|
2017-04-05 20:23:29 +02:00
|
|
|
if before.After(cache.LastCheck) {
|
2017-04-05 19:03:44 +02:00
|
|
|
delete(permissionCache, index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|