1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-27 16:07:42 +08:00

blocks/blockstore: style cleanup of bloomcache

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
Jakub Sztandera
2016-07-04 20:34:46 +02:00
parent e92e6662a7
commit f13506c11a

View File

@ -76,32 +76,36 @@ func (b *bloomcache) DeleteBlock(k key.Key) error {
b.arc.Remove(k) // Invalidate cache before deleting.
err := b.blockstore.DeleteBlock(k)
if err == nil {
switch err {
case nil:
b.arc.Add(k, false)
} else if err == ds.ErrNotFound || err == ErrNotFound {
case ds.ErrNotFound, ErrNotFound:
b.arc.Add(k, false)
return ErrNotFound
default:
return err
}
return err
return nil
}
// if ok == false has is inconclusive
// if ok == true then has respons to question: is it contained
func (b *bloomcache) hasCached(k key.Key) (has bool, ok bool) {
if k == "" {
return true, true
// Return cache invalid so call to blockstore
// in case of invalid key is forwarded deeper
return false, false
}
if b.BloomActive() {
blr := b.bloom.HasTS([]byte(k))
if blr == false { // not contained in bloom is only conclusive answer bloom gives
return blr, true
return false, true
}
}
h, ok := b.arc.Get(k)
if ok {
return h.(bool), ok
} else {
return false, ok
return false, false
}
}