36 lines
755 B
Go
36 lines
755 B
Go
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)
|
||
}
|