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/models/cache_worker.go

26 lines
594 B
Go

package models
import "time"
type CacheWorkerConfig struct {
Every Duration
After Duration
}
func NewCacheWorker(config CacheWorkerConfig) (w *Worker) {
return NewWorker(config.Every.Duration, func() {
// Cache if product exists
for index, cache := range productExistCache {
if cache.LastCheck.After(time.Now().Add(-config.After.Duration)) {
delete(productExistCache, index)
}
}
// Cache for permissions
for index, cache := range permissionCache {
if cache.LastCheck.After(time.Now().Add(-config.After.Duration)) {
delete(permissionCache, index)
}
}
})
}