Closed 2785 closed 1 year ago
I'll take a look. Thanks for the detailed report.
@dgryski any ETA on looking at it?
The cache didn't handle "Add" well if a key was already in the cache. We now detect this case and handle list movements as if it was "Get".
the above snippet prints
bar
andbar
when doing.Add()
on the same key. This seems to be because the code herehttps://github.com/dgryski/go-tinylfu/blob/master/tinylfu.go#L85-L113
t
,t.lru
, andt.slru
all share the same underlyingmap[string]*list.Element
L89 -
t.lru.add
for the new item decides to evict the old item ("bar") becausell.Len()
of 1 is not smaller thanlru.cap
which is also 1 when tinylfu size is 100at L94 the shared
map[string]*list.Element
contains the correct entrybaz
L95
t.slru.victim()
finds no victims to evictL97
t.slru.add(oitem)
adds the old item into the slru and overwrites thebaz
value on the shared map withbar
by the time this function exits the data contains
foo: bar
instead offoo: baz
we do have the work around of deleting prior to adding
I'd give a PR a stab but I don't fully understand how this package works to know what'd be the architecturally correct fix