Add redis for caching, first try during a train ride so expect it to not be working yet

This commit is contained in:
Moritz Marquardt 2024-03-24 20:24:32 +01:00
parent b8b9886ee1
commit 5b6eecc75f
12 changed files with 149 additions and 32 deletions

View file

@ -1,7 +1,31 @@
package cache
import "github.com/OrlovEvgeny/go-mcache"
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)
}
func NewInMemoryCache() ICache {
return mcache.New()
return &MCache{mcache.New()}
}