mirror of https://github.com/status-im/go-waku.git
nit: change to simpleLRU
This commit is contained in:
parent
c890b1fee8
commit
e6d9f6b1d8
|
@ -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())),
|
||||
|
|
Loading…
Reference in New Issue