Support callback when expiring
madokast opened this issue · comments
madokast commented
David Boslee commented
Is this what you had in mind?
type Callback[K comparable, V any] func(K, V)`
The only issue is adding this as a CacheOption
would break the current API since it would require you to specify type contraints for each CacheOption
:
lru.New[int, int](WithCapacity[int, int](1000), WithCallback[int, int](callback))
I suppose we could add a seprate function to add the callback outside of the constructor and maybe golang will support better type inferencing in the future to support the above without the type constraints on each CacheOption
. This would look like:
cache := lru.New[int, int](WithCapacity(1000))
cache.SetCallback[int, int](callback)
This is my preferred option for now to avoid breaking the API.
David Boslee commented
@madokast see above otherwise closing this soon.