scalalang2 / golang-fifo

Modern efficient cache design with simple FIFO queue only in Golang
MIT License
141 stars 7 forks source link

OnEvictCallback called for non-evictions #36

Closed costela closed 2 months ago

costela commented 3 months ago

Currently, the OnEvictCallback callback is called for evictions - as expected - but also for expirations (based on TTL) and manual removals.

Further, the current OnEvictCallback signature does not allow differentiate which of these cases happened.

I propose making a breaking change and either:

Any of these seem acceptable? If yes, I'd cook up a PR.

scalalang2 commented 3 months ago

Hello @costela I'm pleased to see your contribution 🙇

I think that adding a parameter to the function seems fine.

type OnEvictCallback[K comparable, V any] func(key K, value V, expired bool)

The name expired is arbitrarily chosen by me, please suggest a name that makes sense more.

costela commented 3 months ago

A first pass is at https://github.com/scalalang2/golang-fifo/pull/37

PTAL :pray:

scalalang2 commented 3 months ago

Thank you for your work. Once it's merged, I'll tag it with a new release 👍