blocks/blockstore: style cleanup of bloomcache
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Jul 4, 2016 at 20:34 UTC
f13506c11a6f4a953374e8a3af160b668c7126eb
1 file changed
+11
-7
blocks/blockstore/bloom_cache.go
+11
-7
@@ -76,32 +76,36 @@ func (b *bloomcache) DeleteBlock(k key.Key) error {
76
77
b.arc.Remove(k) // Invalidate cache before deleting.
78
err := b.blockstore.DeleteBlock(k)
79
- if err == nil {
79
+ switch err {
80
+ case nil:
81
b.arc.Add(k, false)
81
- } else if err == ds.ErrNotFound || err == ErrNotFound {
82
+ case ds.ErrNotFound, ErrNotFound:
83
b.arc.Add(k, false)
83
- return ErrNotFound
84
+ default:
85
+ return err
86
}
85
- return err
87
+ return nil
88
}
89
90
// if ok == false has is inconclusive
91
// if ok == true then has respons to question: is it contained
92
func (b *bloomcache) hasCached(k key.Key) (has bool, ok bool) {
93
if k == "" {
92
- return true, true
94
+ // Return cache invalid so call to blockstore
95
+ // in case of invalid key is forwarded deeper
96
+ return false, false
97
}
98
if b.BloomActive() {
99
blr := b.bloom.HasTS([]byte(k))
100
if blr == false { // not contained in bloom is only conclusive answer bloom gives
97
- return blr, true
101
+ return false, true
102
}
103
}
104
h, ok := b.arc.Get(k)
105
if ok {
106
return h.(bool), ok
107
} else {
104
- return false, ok
108
+ return false, false
109
}
110
}
111