51 lines
831 B
Go
51 lines
831 B
Go
package cache
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"go.uber.org/fx"
|
|
|
|
"payouts/internal/config"
|
|
"payouts/internal/service/database/orm"
|
|
)
|
|
|
|
var Module = fx.Options(
|
|
fx.Provide(New),
|
|
|
|
fx.Invoke(StartCache),
|
|
)
|
|
|
|
var NoSessionFound = errors.New("no session found")
|
|
|
|
type Service interface {
|
|
PutSession(string, orm.User)
|
|
GetSession(string) (orm.User, error)
|
|
StartBackground()
|
|
}
|
|
|
|
type Params struct {
|
|
fx.In
|
|
|
|
AppConfig *config.App
|
|
}
|
|
|
|
func New(p Params) (Service, error) {
|
|
return NewSessionCache(p.AppConfig.Cache.TTL)
|
|
}
|
|
|
|
// RegisterRoutes registers the api routes and starts the http server
|
|
func StartCache(s Service, lc fx.Lifecycle) {
|
|
lc.Append(fx.Hook{
|
|
OnStart: func(c context.Context) error {
|
|
go func() {
|
|
s.StartBackground()
|
|
}()
|
|
return nil
|
|
},
|
|
OnStop: func(ctx context.Context) error {
|
|
return nil
|
|
},
|
|
})
|
|
}
|