Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support callback when expiring #5

Open
madokast opened this issue Mar 10, 2023 · 2 comments
Open

Support callback when expiring #5

madokast opened this issue Mar 10, 2023 · 2 comments

Comments

@madokast
Copy link

No description provided.

@dboslee
Copy link
Owner

dboslee commented Mar 28, 2023

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.

@dboslee
Copy link
Owner

dboslee commented Jun 1, 2023

@madokast see above otherwise closing this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants