arc cache is threadsafe

This commit is contained in:
whyrusleeping 2019-10-09 21:50:07 +09:00
parent b333247fab
commit bb974d23e6

View File

@ -1,14 +1,11 @@
package chain
import (
"sync"
lru "github.com/hashicorp/golang-lru"
"github.com/ipfs/go-cid"
)
type BadBlockCache struct {
lk sync.Mutex
badBlocks *lru.ARCCache
}
@ -24,13 +21,9 @@ func NewBadBlockCache() *BadBlockCache {
}
func (bts *BadBlockCache) Add(c cid.Cid) {
bts.lk.Lock()
defer bts.lk.Unlock()
bts.badBlocks.Add(c, nil)
}
func (bts *BadBlockCache) Has(c cid.Cid) bool {
bts.lk.Lock()
defer bts.lk.Unlock()
return bts.badBlocks.Contains(c)
}