Files
commander/inmemorycache/inmemorycache.go
2024-08-01 23:42:30 +03:00

31 lines
515 B
Go

package inmemorycache
import (
"time"
"github.com/patrickmn/go-cache"
)
type InMemoryCache struct {
cache *cache.Cache
}
func NewInMemoryCache() *InMemoryCache {
return &InMemoryCache{cache: cache.New(time.Minute, 5*time.Minute)}
}
func (i *InMemoryCache) Set(key string, value []byte, ttl time.Duration) error {
i.cache.Set(key, value, ttl)
return nil
}
func (i *InMemoryCache) Get(key string) ([]byte, error) {
res, ok := i.cache.Get(key)
if !ok {
return nil, nil
}
return res.([]byte), nil
}