@@ -140,18 +140,42 @@ var cacheProviderSet = wire.NewSet(
140140 newClaimsCache ,
141141)
142142
143- func newClaimsCache (conn * nats.Conn ) (cache.Cache [* jwt.MapClaims ], error ) {
144- opts := []cache.Option {cache .WithTTL (10 * time .Second )}
143+ func newClaimsCache (conn * nats.Conn , logger log.Logger ) (cache.Cache [* jwt.MapClaims ], error ) {
144+ l := log .NewHelper (logger )
145+ backend := "memory"
146+ opts := []cache.Option {cache .WithTTL (10 * time .Second ), cache .WithLogger (& kratosLogAdapter {h : l })}
145147 if conn != nil {
146- opts = append (opts , cache .WithNATS (conn , "jwt-claims" ))
148+ backend = "nats"
149+ opts = append (opts , cache .WithNATS (conn , "chainloop-jwt-claims" ))
147150 }
151+ l .Infow ("msg" , "cache initialized" , "bucket" , "chainloop-jwt-claims" , "backend" , backend , "ttl" , "10s" )
148152 return cache .New [* jwt.MapClaims ](opts ... )
149153}
150154
151- func newMembershipsCache (conn * nats.Conn ) (cache.Cache [* entities.Membership ], error ) {
152- opts := []cache.Option {cache .WithTTL (time .Second )}
155+ func newMembershipsCache (conn * nats.Conn , logger log.Logger ) (cache.Cache [* entities.Membership ], error ) {
156+ l := log .NewHelper (logger )
157+ backend := "memory"
158+ opts := []cache.Option {cache .WithTTL (time .Second ), cache .WithLogger (& kratosLogAdapter {h : l })}
153159 if conn != nil {
154- opts = append (opts , cache .WithNATS (conn , "memberships" ))
160+ backend = "nats"
161+ opts = append (opts , cache .WithNATS (conn , "chainloop-memberships" ))
155162 }
163+ l .Infow ("msg" , "cache initialized" , "bucket" , "chainloop-memberships" , "backend" , backend , "ttl" , "1s" )
156164 return cache .New [* entities.Membership ](opts ... )
157165}
166+
167+ // kratosLogAdapter adapts kratos log.Helper (Debugw(...interface{})) to cache.Logger (Debugw(string, ...any)).
168+ type kratosLogAdapter struct { h * log.Helper }
169+
170+ func (a * kratosLogAdapter ) Debugw (msg string , keyvals ... any ) {
171+ a .h .Debugw (append ([]any {"msg" , msg }, keyvals ... )... )
172+ }
173+ func (a * kratosLogAdapter ) Infow (msg string , keyvals ... any ) {
174+ a .h .Infow (append ([]any {"msg" , msg }, keyvals ... )... )
175+ }
176+ func (a * kratosLogAdapter ) Warnw (msg string , keyvals ... any ) {
177+ a .h .Warnw (append ([]any {"msg" , msg }, keyvals ... )... )
178+ }
179+ func (a * kratosLogAdapter ) Errorw (msg string , keyvals ... any ) {
180+ a .h .Errorw (append ([]any {"msg" , msg }, keyvals ... )... )
181+ }
0 commit comments