-
Notifications
You must be signed in to change notification settings - Fork 3
/
cache.go
33 lines (28 loc) · 1.38 KB
/
cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package test
import (
"github.com/alexfalkowski/go-service/cache/redis"
"github.com/alexfalkowski/go-service/cache/redis/trace/opentracing"
cristretto "github.com/alexfalkowski/go-service/cache/ristretto"
"github.com/alexfalkowski/go-service/compressor"
"github.com/alexfalkowski/go-service/marshaller"
"github.com/dgraph-io/ristretto"
"github.com/go-redis/cache/v8"
"go.uber.org/fx"
"go.uber.org/zap"
)
// NewRedisCache for test.
func NewRedisCache(lc fx.Lifecycle, host string, logger *zap.Logger, compressor compressor.Compressor, marshaller marshaller.Marshaller) *cache.Cache {
tracer, _ := opentracing.NewTracer(opentracing.TracerParams{Lifecycle: lc, Config: NewJaegerConfig(), Version: Version})
cfg := &redis.Config{Host: host}
client := redis.NewClient(redis.ClientParams{Lifecycle: lc, RingOptions: redis.NewRingOptions(cfg), Tracer: tracer, Logger: logger})
params := redis.OptionsParams{Client: client, Compressor: compressor, Marshaller: marshaller}
opts := redis.NewOptions(params)
return redis.NewCache(redis.CacheParams{Lifecycle: lc, Config: cfg, Options: opts, Version: Version})
}
// NewRistrettoCache for test.
// nolint:gomnd
func NewRistrettoCache(lc fx.Lifecycle) *ristretto.Cache {
cfg := &cristretto.Config{NumCounters: 1e7, MaxCost: 1 << 30, BufferItems: 64}
c, _ := cristretto.NewCache(cristretto.CacheParams{Lifecycle: lc, Config: cfg, Version: Version})
return c
}