finclip-app-manager/vendor/gitlab.finogeeks.club/finclip-backend/mop-middleware-auth/mem_cache.go

36 lines
755 B
Go
Raw Normal View History

2023-11-02 18:36:36 +08:00
package mop_middleware_auth
import (
"errors"
goCache "github.com/patrickmn/go-cache"
"time"
)
//目前对 secret、bindingId、organId做了缓存放在内存中
var memCache *goCache.Cache
func init() {
memCache = goCache.New(0, 0)
}
func SetMemCache(key string, value interface{}) {
memCache.Set(key, value, goCache.DefaultExpiration)
}
func SetMemCacheWithTime(key string, value interface{}, time time.Duration) {
memCache.Set(key, value, time)
}
func GetMemCache(key string) (interface{}, bool) {
return memCache.Get(key)
}
func GetMemCacheWithDelete(key string) (interface{}, error) {
value, found := memCache.Get(key)
if found {
go memCache.Delete(key)
return value, nil
}
return nil, errors.New("Not Found, key=" + key)
}