2017-05-03 08:02:29 +02:00
|
|
|
// Package with supporting functionality to run the microservice
|
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-05-03 08:02:29 +02:00
|
|
|
// Configuration of the cache Worker
|
2017-04-07 11:56:28 +02:00
|
|
|
var CacheConfig models.CacheWorkerConfig
|
2017-04-05 19:03:44 +02:00
|
|
|
|
2017-05-03 08:02:29 +02:00
|
|
|
// Function to run the cache Worker
|
2017-04-07 11:32:49 +02:00
|
|
|
func CleanCache() {
|
|
|
|
before := time.Now().Add(-CacheConfig.After.Duration)
|
2017-05-03 08:02:29 +02:00
|
|
|
// Cache, if product exists
|
2017-04-07 11:32:49 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2017-04-28 10:27:36 +02:00
|
|
|
|
2017-05-03 08:02:29 +02:00
|
|
|
// Function to create a Worker and to clean the caches from other microservice
|
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
|
|
|
}
|