genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0
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.
hs_monolith/runtime/cache_worker.go

34 lines
835 B
Go
Raw Normal View History

package runtime
import (
"time"
"github.com/genofire/hs_master-kss-monolith/lib/worker"
"github.com/genofire/hs_master-kss-monolith/models"
)
2017-04-28 10:27:36 +02:00
// config of the cache worker
var CacheConfig models.CacheWorkerConfig
2017-04-28 10:27:36 +02:00
// command which is runned in the cache worker
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)
}
}
// Cache for permissions
for index, cache := range permissionCache {
if before.After(cache.LastCheck) {
delete(permissionCache, index)
}
}
}
2017-04-28 10:27:36 +02:00
// create a worker to clean the caches which stored from other microservice
func NewCacheWorker() (w *worker.Worker) {
return worker.NewWorker(CacheConfig.Every.Duration, CleanCache)
}