-
Notifications
You must be signed in to change notification settings - Fork 0
/
bucket_expire.go
46 lines (44 loc) · 1.04 KB
/
bucket_expire.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cbytecache
// Mark all entries on range [0..z) as expired.
//
// This method has sense only if expire listener is provided in config.
func (b *bucket) expireRange(z int) {
el := b.elen()
if z < 256 {
_ = b.entry[el-1]
for i := 0; i < z; i++ {
b.expire(&b.entry[i])
}
} else {
z8 := z - z%8
_ = b.entry[el-1]
for i := 0; i < z8; i += 8 {
b.expire(&b.entry[i])
b.expire(&b.entry[i+1])
b.expire(&b.entry[i+2])
b.expire(&b.entry[i+3])
b.expire(&b.entry[i+4])
b.expire(&b.entry[i+5])
b.expire(&b.entry[i+6])
b.expire(&b.entry[i+7])
}
for i := z8; i < z; i++ {
b.expire(&b.entry[i])
}
}
}
// Perform expire operation over single entry.
func (b *bucket) expire(e *entry) {
if e.invalid() {
return
}
// Get entry data (key, body and expire timestamp).
b.buf.ResetLen()
_ = b.buf.GrowLen(int(e.length))
key, body, err := b.getLF(b.buf.Bytes()[:0], e, dummyMetrics)
if err != nil {
return
}
// Pack entry and send it to the listener.
_ = b.config.ExpireListener.Listen(Entry{Key: key, Body: body})
}