@@ -206,17 +206,18 @@ type flatentry struct {
206
206
207
207
func (f * flatentry ) insert (e * flatentry ) {
208
208
f .size += e .size
209
+ f .ttl = e .ttl
209
210
f .mu .Lock ()
210
211
e .ovfl = f .ovfl
211
212
f .ovfl = e
212
213
f .mu .Unlock ()
213
214
}
214
215
215
216
func (f * flatentry ) find (cmd string , ts int64 ) ([]byte , bool ) {
217
+ if f != nil && ts >= f .ttl {
218
+ return nil , true
219
+ }
216
220
for next := f ; next != nil ; {
217
- if ts >= next .ttl {
218
- return nil , true
219
- }
220
221
if cmd == next .cmd {
221
222
return next .val , false
222
223
}
@@ -232,7 +233,7 @@ const lrBatchSize = 64
232
233
const flattEntrySize = unsafe .Sizeof (flatentry {})
233
234
234
235
type lrBatch struct {
235
- m map [* flatentry ]bool
236
+ m map [* flatentry ]struct {}
236
237
}
237
238
238
239
func NewFlattenCache (limit int ) CacheStore {
@@ -247,7 +248,7 @@ func NewFlattenCache(limit int) CacheStore {
247
248
f .head .next = unsafe .Pointer (f .tail )
248
249
f .tail .prev = unsafe .Pointer (f .head )
249
250
f .lrup = sync.Pool {New : func () any {
250
- b := & lrBatch {m : make (map [* flatentry ]bool , lrBatchSize )}
251
+ b := & lrBatch {m : make (map [* flatentry ]struct {} , lrBatchSize )}
251
252
runtime .SetFinalizer (b , func (b * lrBatch ) {
252
253
if len (b .m ) >= 0 {
253
254
f .mu .Lock ()
@@ -292,13 +293,9 @@ func (f *flatten) llTail(e *flatentry) {
292
293
}
293
294
294
295
func (f * flatten ) llTailBatch (b * lrBatch ) {
295
- for e , expired := range b .m {
296
+ for e := range b .m {
296
297
if e .mark == f .mark {
297
- if expired {
298
- f .remove (e )
299
- } else {
300
- f .llTail (e )
301
- }
298
+ f .llTail (e )
302
299
}
303
300
}
304
301
clear (b .m )
@@ -315,20 +312,18 @@ func (f *flatten) Flight(key, cmd string, ttl time.Duration, now time.Time) (Red
315
312
e := f .cache [key ]
316
313
f .mu .RUnlock ()
317
314
ts := now .UnixMilli ()
318
- if v , expired := e .find (cmd , ts ); v != nil || expired {
315
+ if v , _ := e .find (cmd , ts ); v != nil {
319
316
batch := f .lrup .Get ().(* lrBatch )
320
- batch .m [e ] = expired
317
+ batch .m [e ] = struct {}{}
321
318
if len (batch .m ) >= lrBatchSize {
322
319
f .mu .Lock ()
323
320
f .llTailBatch (batch )
324
321
f .mu .Unlock ()
325
322
}
326
323
f .lrup .Put (batch )
327
- if v != nil {
328
- var ret RedisMessage
329
- _ = ret .CacheUnmarshalView (v )
330
- return ret , nil
331
- }
324
+ var ret RedisMessage
325
+ _ = ret .CacheUnmarshalView (v )
326
+ return ret , nil
332
327
}
333
328
fk := key + cmd
334
329
f .mu .RLock ()
0 commit comments