func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
	if len(key) <= 0 || len(val) <= 0 {
		return nil
	}
	var expire int64
	if exp != 0 {
		expire = time.Now().Add(exp).Unix()
	}
	s.mux.Lock()
	s.db[key] = entry{val, expire}
	s.mux.Unlock()
	return nil
}
Set key with value
Set key with value
package memory
import (
	"sync"
	"time"
)
type Storage struct {
	mux        sync.RWMutex
	db         map[string]entry
	gcInterval time.Duration
	done       chan struct{}
}
type entry struct {
	data   []byte
	expiry int64
}
func New(config ...Config) *Storage {
	cfg := configDefault(config...)
	store := &Storage{
		db:         make(map[string]entry),
		gcInterval: cfg.GCInterval,
		done:       make(chan struct{}),
	}
	go store.gc()
	return store
}
func (s *Storage) Get(key string) ([]byte, error) {
	if len(key) <= 0 {
		return nil, nil
	}
	s.mux.RLock()
	v, ok := s.db[key]
	s.mux.RUnlock()
	if !ok || v.expiry != 0 && v.expiry <= time.Now().Unix() {
		return nil, nil
	}
	return v.data, nil
}