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

call expirationCallback automatically on cache.Close() #28

Closed
LihuaWu opened this issue Jul 9, 2020 · 8 comments
Closed

call expirationCallback automatically on cache.Close() #28

LihuaWu opened this issue Jul 9, 2020 · 8 comments

Comments

@LihuaWu
Copy link

LihuaWu commented Jul 9, 2020

Is it possible to call expirationCallback on each remaining keys in the cache, when calling cache.Close()?

The purpose is to keep the overall expirationCallback behavior the same?

@LihuaWu
Copy link
Author

LihuaWu commented Jul 9, 2020

@ReneKroon
Thanks for your time.

@ReneKroon
Copy link
Contributor

Good idea, will have to check the feasibility first.

ReneKroon pushed a commit that referenced this issue Jul 9, 2020
@ReneKroon
Copy link
Contributor

@LihuaWu can you test if this solves the issue for you? I added code to run all expiration callbacks on Close() including a test to verify this.

@LihuaWu
Copy link
Author

LihuaWu commented Jul 10, 2020

@ReneKroon
I have looked at the unit test, and thanks for your quick feedback.
Would it be better for cache.Close to wait all expirationCallback functions executed before it returns?
Currently, it will just start a new goroutine for each expirationCallback function to execute, and thus it is not possible to know when all expirationCallback calls will be finished.

@ReneKroon
Copy link
Contributor

I'd say it's a fair request, however during normal operation the expiration is async and this would imply that any items cleaned up just before calling cache.Close are still maybe executing the handler, while the synchronous callbacks are already done. This would create a race condition as it's not guaranteed that all callbacks have completed once cache.Close returns. I'd suggest using sync.WaitGroup inside the callback to keep track of callback's in progress. Would that work in your case?

@LihuaWu
Copy link
Author

LihuaWu commented Jul 15, 2020

@ReneKroon
I think you are right, and it makes sense to keep the callbacks in async.
Synchronous callbacks are only special cases for the cache.Close operation.
And keeping track of progress in the callback is a viable option for me.
Thanks!

@LihuaWu
Copy link
Author

LihuaWu commented Jul 15, 2020

@ReneKroon and I have no further concerns.

@ReneKroon
Copy link
Contributor

Ok, will release this officially then.

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