More stuff

This commit is contained in:
Melody Becker 2024-09-15 15:18:05 +02:00
parent 71beed7eb3
commit 9a7e420c83
7 changed files with 63 additions and 33 deletions

View file

@ -12,6 +12,7 @@ import (
ristretto_store "github.com/eko/gocache/store/ristretto/v4"
"github.com/redis/go-redis/v9"
"github.com/rs/zerolog/log"
"gitlab.com/mstarongitlab/linstrom/config"
)
type Cache struct {
@ -37,7 +38,9 @@ func NewCache(maxSize int64, redisUrl *string) (*Cache, error) {
}
ristrettoStore := ristretto_store.NewRistretto(
ristrettoCache,
store.WithExpiration(time.Second*10),
store.WithExpiration(
time.Second*time.Duration(config.GlobalConfig.Storage.MaxInMemoryCacheSize),
),
)
var cacheManager *cache.ChainCache[[]byte]
@ -47,7 +50,12 @@ func NewCache(maxSize int64, redisUrl *string) (*Cache, error) {
return nil, err
}
redisClient := redis.NewClient(opts)
redisStore := redis_store.NewRedis(redisClient, store.WithExpiration(time.Minute))
redisStore := redis_store.NewRedis(
redisClient,
store.WithExpiration(
time.Second*time.Duration(*config.GlobalConfig.Storage.MaxRedisCacheTTL),
),
)
cacheManager = cache.NewChain(
cache.New[[]byte](ristrettoStore),
cache.New[[]byte](redisStore),