123456789101112131415161718192021222324252627282930313233 |
- package cache
- import (
- "context"
- "github.com/patrickmn/go-cache"
- "time"
- )
- type MemCache struct {
- engine *cache.Cache
- }
- func (cache *MemCache) Set(ctx context.Context, key string, value any) {
- cache.engine.Set(key, value, 0)
- }
- func (cache *MemCache) SetEx(ctx context.Context, key string, value any, expire time.Duration) {
- cache.engine.Set(key, value, expire)
- }
- func (cache *MemCache) Get(ctx context.Context, key string) (value any, ok bool) {
- return cache.engine.Get(key)
- }
- func (cache *MemCache) Del(ctx context.Context, key string) {
- cache.engine.Delete(key)
- }
- func NewMemCache() *MemCache {
- return &MemCache{
- engine: cache.New(time.Hour, time.Minute*90),
- }
- }
|