2021-12-03 03:15:48 +00:00
|
|
|
package cache
|
|
|
|
|
2024-03-24 19:24:32 +00:00
|
|
|
import (
|
|
|
|
"github.com/OrlovEvgeny/go-mcache"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MCache struct {
|
|
|
|
mcache *mcache.CacheDriver
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MCache) Set(key string, value string, ttl time.Duration) error {
|
|
|
|
return m.mcache.Set(key, value, ttl)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MCache) Get(key string) (string, bool) {
|
|
|
|
val, ok := m.mcache.Get(key)
|
|
|
|
if ok {
|
|
|
|
return val.(string), true
|
|
|
|
} else {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MCache) Remove(key string) {
|
|
|
|
m.mcache.Remove(key)
|
|
|
|
}
|
2021-12-03 03:15:48 +00:00
|
|
|
|
2024-02-15 16:08:29 +00:00
|
|
|
func NewInMemoryCache() ICache {
|
2024-03-24 19:24:32 +00:00
|
|
|
return &MCache{mcache.New()}
|
2021-12-03 03:15:48 +00:00
|
|
|
}
|