From e6d9f6b1d815ef9808a106f28b3672ce2103a6d5 Mon Sep 17 00:00:00 2001 From: harsh-98 Date: Thu, 4 May 2023 17:33:13 +0530 Subject: [PATCH] nit: change to simpleLRU --- waku/v2/protocol/peer_exchange/enr_cache.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/waku/v2/protocol/peer_exchange/enr_cache.go b/waku/v2/protocol/peer_exchange/enr_cache.go index 382a9d5b..af8f1423 100644 --- a/waku/v2/protocol/peer_exchange/enr_cache.go +++ b/waku/v2/protocol/peer_exchange/enr_cache.go @@ -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())),