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

Feature Request: PurgeExpire() #37

Closed
sean- opened this issue Jul 5, 2017 · 0 comments
Closed

Feature Request: PurgeExpire() #37

sean- opened this issue Jul 5, 2017 · 0 comments

Comments

@sean-
Copy link
Contributor

sean- commented Jul 5, 2017

The current behavior of Purge() is such that the EvictedFunc() is not called when items are removed from the cache (the cached items lists are just replaced and handed off to the GC). Without a higher-level locking primitive, there is not a way to purge a cache and call the evict handler.

It would be nice if the interface was updated to include PurgeExpire() that would take c.mu.Lock() and, if evictedFunc() is not nil, call GetALL() + evictedFunc() on each of the items while c.mu held and before c.init() is called.

Or Purge() could be updated to implicitly call evictFunc() on each item. Without this change to make Purge() symmetric w/ calls to LoaderFunc(), it is difficult to use this cache for finite resources (e.g. file descriptors). Resorting to finalizers used in the LoaderFunc() feels very distasteful and like a hack.

I'm happy to PR this change but want to inquire re: the API first before submitting a PR.

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

1 participant