2023-04-23 17:57:36 +08:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
std Cache
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
std = NewMemCache()
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetCache(l Cache) {
|
|
|
|
std = l
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetCache() Cache {
|
|
|
|
return std
|
|
|
|
}
|
|
|
|
|
|
|
|
func Set(ctx context.Context, key string, value any) {
|
|
|
|
std.Set(ctx, key, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetEx(ctx context.Context, key string, value any, expire time.Duration) {
|
|
|
|
std.SetEx(ctx, key, value, expire)
|
|
|
|
}
|
|
|
|
|
2023-06-30 14:16:16 +08:00
|
|
|
func Try(ctx context.Context, key string, cb LoadFunc) (value any, err error) {
|
|
|
|
return std.Try(ctx, key, cb)
|
|
|
|
}
|
|
|
|
|
2023-04-23 17:57:36 +08:00
|
|
|
func Get(ctx context.Context, key string) (value any, ok bool) {
|
|
|
|
return std.Get(ctx, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Del(ctx context.Context, key string) {
|
|
|
|
std.Del(ctx, key)
|
|
|
|
}
|