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

What about a ExpirationPolicy.ONLY_IF_ACCESSED? #47

Open
mishaxz opened this issue Apr 22, 2017 · 5 comments
Open

What about a ExpirationPolicy.ONLY_IF_ACCESSED? #47

mishaxz opened this issue Apr 22, 2017 · 5 comments

Comments

@mishaxz
Copy link

mishaxz commented Apr 22, 2017

  1. entry expires only if it has been accessed
  2. this could be useful especially in conjunciton with .maxSize to expire entries only a set time after they have been accessed but maxSize prevents the map from growing out of control
  3. in some unpredictable situations (like waiting for responses across the network), this could be useful when you need to keep some data in a map until you receive a confirmation request. Then you don't need it for much longer afterwards because your code is not depending upon external slowdown factors
@jhalterman
Copy link
Owner

How would this be different than ExpirationPolicy.ACCESSED?

@mishaxz
Copy link
Author

mishaxz commented Apr 22, 2017

I was under the impression that ACCESSED will expire entries even if they are never accessed?

@jhalterman
Copy link
Owner

jhalterman commented Apr 22, 2017

That's right - so how would ONLY_IF_ACCESSED work - start the timer for an entry after it's accessed for the first time, and reset after each subsequent access?

@mishaxz
Copy link
Author

mishaxz commented Apr 22, 2017

nah, I was just thinking leave it in the map.. and if it is never accessed, it never expires. However, to prevent it from growing out of control the user could set maxSize to have it expire entries that way (just in case)

however, probably a good idea to throw an exception if maxSize is not set to be very safe )

ok maybe this feature is a "would be nice" thing that could cause problems...

@Nohus
Copy link

Nohus commented Nov 4, 2017

This would indeed be useful, with such a policy there would be no need for any timers/threads. The expiration time would only be checked when the entry is accessed to check if it should be returned or not. It would decrease the overhead and complexity of the ExpiringMap while still being useful when the map size growing too big is not a concern.

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

3 participants