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

36 lines
755 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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)
}