Skip to content

Commit

Permalink
fix slice cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mazrean committed Feb 25, 2023
1 parent 8e5e219 commit bb66c2a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cache/sc.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,16 @@ func NewSlice[T any](name string, init []T, size int) *Slice[T] {
return m
}

func (s *Slice[T]) Set(index int, value T) {
s.locker.Lock()
s.s[index] = value

if s.lengthMetrics != nil {
s.lengthMetrics.Set(float64(len(s.s)))
}
s.locker.Unlock()
}

func (s *Slice[T]) Get(i int) (T, bool) {
if s.indexMetrics != nil {
s.indexMetrics.Observe(float64(i))
Expand Down

0 comments on commit bb66c2a

Please sign in to comment.