usermngmt/cache/cache.go

30 lines
477 B
Go
Raw Normal View History

2021-11-11 03:20:08 +00:00
package cache
import (
"log"
"time"
"github.com/allegro/bigcache/v3"
)
2021-11-11 09:58:44 +00:00
var mc *bigcache.BigCache
2021-11-11 03:20:08 +00:00
// Init ...
func Init() {
2021-11-11 08:16:17 +00:00
// The time after which entries can be evicted is 30 days
const cacheTime = 24 * 30 * time.Hour // 30 days
c, err := bigcache.NewBigCache(bigcache.DefaultConfig(cacheTime))
2021-11-11 03:20:08 +00:00
if err != nil {
log.Fatalf("Cannot init Cache %v", err)
}
2021-11-11 09:58:44 +00:00
mc = c
2021-11-11 08:16:17 +00:00
// Cache roles
Roles()
2021-11-11 03:20:08 +00:00
}
// GetInstance ...
func GetInstance() *bigcache.BigCache {
2021-11-11 09:58:44 +00:00
return mc
2021-11-11 03:20:08 +00:00
}