nit: change to simpleLRU

This commit is contained in:
harsh-98 2023-05-04 17:33:13 +05:30 committed by RichΛrd
parent c890b1fee8
commit e6d9f6b1d8
1 changed files with 4 additions and 4 deletions

View File

@ -7,21 +7,21 @@ import (
"sync"
"github.com/ethereum/go-ethereum/p2p/enode"
lru "github.com/hashicorp/golang-lru"
"github.com/hashicorp/golang-lru/simplelru"
"github.com/waku-org/go-waku/waku/v2/protocol/peer_exchange/pb"
)
// there is Arccache which is also thread safe but it is too verbose for the use-case and adds unnecessary overhead
// simpleLRU internal uses container/list, which is ring buffer(double linked list)
type enrCache struct {
// using lru, saves us from periodically cleaning the cache to maintain a certain size
data *lru.Cache
data *simplelru.LRU
rng *rand.Rand
mu sync.RWMutex
}
// err on negative size
func newEnrCache(size int) (*enrCache, error) {
inner, err := lru.New(size)
inner, err := simplelru.NewLRU(size, nil)
return &enrCache{
data: inner,
rng: rand.New(rand.NewSource(rand.Int63())),