2017-04-07 11:56:28 +02:00
|
|
|
package runtime
|
2017-04-05 19:03:44 +02:00
|
|
|
|
2017-04-05 20:23:29 +02:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/genofire/hs_master-kss-monolith/lib/worker"
|
2017-04-07 11:56:28 +02:00
|
|
|
"github.com/genofire/hs_master-kss-monolith/models"
|
2017-04-05 20:23:29 +02:00
|
|
|
)
|
|
|
|
|
2017-04-07 11:56:28 +02:00
|
|
|
var CacheConfig models.CacheWorkerConfig
|
2017-04-05 19:03:44 +02:00
|
|
|
|
2017-04-07 11:32:49 +02:00
|
|
|
func CleanCache() {
|
|
|
|
before := time.Now().Add(-CacheConfig.After.Duration)
|
|
|
|
// Cache if product exists
|
|
|
|
for index, cache := range productExistCache {
|
|
|
|
if before.After(cache.LastCheck) {
|
|
|
|
delete(productExistCache, index)
|
2017-04-05 19:03:44 +02:00
|
|
|
}
|
2017-04-07 11:32:49 +02:00
|
|
|
}
|
|
|
|
// Cache for permissions
|
|
|
|
for index, cache := range permissionCache {
|
|
|
|
if before.After(cache.LastCheck) {
|
|
|
|
delete(permissionCache, index)
|
2017-04-05 19:03:44 +02:00
|
|
|
}
|
2017-04-07 11:32:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
func NewCacheWorker() (w *worker.Worker) {
|
|
|
|
return worker.NewWorker(CacheConfig.Every.Duration, CleanCache)
|
2017-04-05 19:03:44 +02:00
|
|
|
}
|