2021-11-11 03:20:08 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/allegro/bigcache/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
var cache *bigcache.BigCache
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
cache = 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 {
|
|
|
|
return cache
|
|
|
|
}
|