Skip to content

Commit

Permalink
perf: use constructor for default lru, lazy init it
Browse files Browse the repository at this point in the history
  • Loading branch information
Semior001 committed Jun 10, 2024
1 parent 3fb5481 commit 895ba48
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ type Interceptor struct {

// NewInterceptor makes a new Interceptor.
func NewInterceptor(opts ...Option) *Interceptor {
l, _ := lru.New[string, Entry](1024)

c := &Interceptor{
codec: RawBytesCodec{},
logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
store: lruWrapper{backend: l},
filter: regexp.MustCompile(`.*`),
}

for _, opt := range opts {
opt(c)
}

if c.store == nil { // lazy init for LRU
l, _ := lru.New[string, Entry](1024)
c.store = NewLRU(l)
}

return c
}

Expand Down

0 comments on commit 895ba48

Please sign in to comment.