mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
swarm/storage: fix setCapacity for 0
This commit is contained in:
parent
9a40655aa6
commit
a43c8a9c36
1 changed files with 20 additions and 2 deletions
|
|
@ -32,9 +32,16 @@ const (
|
|||
type MemStore struct {
|
||||
//cache *lru.ARCCache
|
||||
cache *lru.Cache
|
||||
disabled bool
|
||||
}
|
||||
|
||||
func NewMemStore(_ *LDBStore, capacity uint) (m *MemStore) {
|
||||
if capacity == 0 {
|
||||
return &MemStore{
|
||||
disabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
onEvicted := func(key interface{}, value interface{}) {
|
||||
v := value.(*Chunk)
|
||||
<-v.dbStoredC
|
||||
|
|
@ -51,6 +58,10 @@ func NewMemStore(_ *LDBStore, capacity uint) (m *MemStore) {
|
|||
}
|
||||
|
||||
func (m *MemStore) Get(key Key) (*Chunk, error) {
|
||||
if m.disabled {
|
||||
return nil, ErrChunkNotFound
|
||||
}
|
||||
|
||||
c, ok := m.cache.Get(string(key))
|
||||
if !ok {
|
||||
return nil, ErrChunkNotFound
|
||||
|
|
@ -63,11 +74,18 @@ func (m *MemStore) Get(key Key) (*Chunk, error) {
|
|||
}
|
||||
|
||||
func (m *MemStore) Put(c *Chunk) {
|
||||
if m.disabled {
|
||||
return
|
||||
}
|
||||
m.cache.Add(string(c.Key), c)
|
||||
}
|
||||
|
||||
func (m *MemStore) setCapacity(n int) {
|
||||
//no-op
|
||||
if n <= 0 {
|
||||
m.disabled = true
|
||||
} else {
|
||||
m = NewMemStore(nil, uint(n))
|
||||
}
|
||||
}
|
||||
|
||||
// Close memstore
|
||||
|
|
|
|||
Loading…
Reference in a new issue