-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: introduce a ttl cache for resources #482
Conversation
c98d973
to
97f8068
Compare
r := c.resources[instanceID] | ||
delete(c.resources, instanceID) | ||
delete(c.checkouts, instanceID) | ||
go c.cleanup(r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the lack of synchronization create issues here? Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using another go-routine so that the main go-routine is not blocked. At this point no one should be using the resource, thus doing async cleanup should be safe
c4f3b44
to
fafd33c
Compare
Description
Introducing a new specialty cache for resources which need to be closed/cleaned-up after their expiration.
This new cache keeps track of the resources' usage and makes sure that expired resources are not cleaned up while they are still in use and cleaned up only when they are no longer needed.
Internally it uses a
cachettl.Cache
which has been extended with anOnEvicted
callback.Resources with any of following methods can be managed by the cache and cleaned up appropriately:
Cleanup()
Close()
Close() error
Stop()
Stop() error
Security