Skip to content

Commit

Permalink
more setup for response caching
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps committed May 20, 2022
1 parent b466eb9 commit 1a5010c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
31 changes: 25 additions & 6 deletions cmd/flipt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import (
"github.com/markphelps/flipt/internal/telemetry"
pb "github.com/markphelps/flipt/rpc/flipt"
"github.com/markphelps/flipt/server"
"github.com/markphelps/flipt/server/cache"
"github.com/markphelps/flipt/server/cache/memory"
"github.com/markphelps/flipt/server/cache/redis"
"github.com/markphelps/flipt/storage"

"github.com/markphelps/flipt/storage/sql"
"github.com/markphelps/flipt/storage/sql/mysql"
"github.com/markphelps/flipt/storage/sql/postgres"
Expand Down Expand Up @@ -386,7 +388,27 @@ func run(_ []string) error {

logger = logger.WithField("store", store.String())

var tracer opentracing.Tracer = &opentracing.NoopTracer{}
var opts []server.Option

if cfg.CacheConfig.Enabled {
var cacher cache.Cacher

switch cfg.CacheConfig.Backend {
case cfg.CacheMemory:
cacher = memory.NewCache(cfg.CacheConfig)
case cfg.CacheRedis:
// r := goredis.NewCache
cacher = redis.NewCache(cfg.CacheConfig, nil)
}

opts = append(opts, server.WithCache(cacher))
}

var (
srv = server.New(logger, store, opts...)

tracer opentracing.Tracer = &opentracing.NoopTracer{}
)

if cfg.Tracing.Jaeger.Enabled {
jaegerCfg := jaeger_config.Configuration{
Expand Down Expand Up @@ -414,10 +436,7 @@ func run(_ []string) error {

opentracing.SetGlobalTracer(tracer)

var (
grpcOpts []grpc.ServerOption
srv = server.New(logger, store)
)
var grpcOpts []grpc.ServerOption

grpcOpts = append(grpcOpts, grpc_middleware.WithUnaryServerChain(
grpc_recovery.UnaryServerInterceptor(),
Expand Down
2 changes: 0 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ func Load(path string) (*Config, error) {
if viper.GetBool(cacheMemoryEnabled) {
cfg.Cache.Backend = CacheMemory
cfg.Cache.Enabled = true
// TODO: log deprecated
} else if viper.IsSet(cacheEnabled) {
cfg.Cache.Enabled = viper.GetBool(cacheEnabled)
if viper.IsSet(cacheBackend) {
Expand All @@ -335,7 +334,6 @@ func Load(path string) (*Config, error) {
case CacheMemory:
if viper.IsSet(cacheMemoryExpiration) {
cfg.Cache.TTL = viper.GetDuration(cacheMemoryExpiration)
// TODO: log deprecated
}
if viper.IsSet(cacheMemoryEvictionInterval) {
cfg.Cache.Memory.EvictionInterval = viper.GetDuration(cacheMemoryEvictionInterval)
Expand Down
1 change: 1 addition & 0 deletions server/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// GetFlag gets a flag
func (s *Server) GetFlag(ctx context.Context, r *flipt.GetFlagRequest) (*flipt.Flag, error) {
s.logger.WithField("request", r).Debug("get flag")
// TODO: get with cache
flag, err := s.store.GetFlag(ctx, r.Key)
s.logger.WithField("response", flag).Debug("get flag")
return flag, err
Expand Down

0 comments on commit 1a5010c

Please sign in to comment.