initial commit
This commit is contained in:
30
inmemorycache/inmemorycache.go
Normal file
30
inmemorycache/inmemorycache.go
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user