-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
refreshAfterWrite returns stale value forever with long load times #175
Comments
Can you also try with an long refreshWriteTime = isAsync ? (now + Async.MAXIMUM_EXPIRY) : now; in You can use the |
Indeed that seems to work:
Updated to make sure that load is still being called (it is). |
Okay. So I think what is happening is that when a refresh is needed, it CASes to the new write time to avoid a stampede of multiple. Then when the refresh completes it sets to the new value if the write timestamp matches. That way if you refresh but then insert, it won't stampede your insert and drop the refresh instead as likely a stale db read. Here it gets stuck because each new refresh being triggered causes the timestamp to increase, so the previous are dropped and the oldest value is kept until the last refresh completes. The async version is so far into the future that it won't hit that problem. All of this is because we don't have a place to stash the Future. In Guava the hash table entry is subclassed with a special version for loading. That way the extra field(s) are only on the computing entry rather than on every single one. Caffeine doesn't fork the hash table so we can't do that, meaning I hacked the It sounds like the resolution is to make it work like Async, add a unit test, and get a release out. I'll try to do that tonight if possible. |
Makes sense, thanks so much! |
Thanks @ben-manes, any chance we could get a release soon? |
Yeah, just stealing time on the train and work trying to wrap it up. I'll release today when I get a chance. |
Released. It may take up to 2 hours for Maven Central to sync with staging. Thanks for the bug report and sorry for any frustrations this caused. |
No, thank you for the quick turn around! |
We have observed that Caffeine may be stuck in a state where it constantly returns the old value if the loading time of a value is longer than the refreshAfterWrite time. We ran this in 2.4.0.
The following code demonstrates the issue:
The output suggests that cache.get("hello") returns the value of 2 where as the atomic integer is returning a value much higher than that. In fact, after running for a long time, cache.get("hello") continues to return a value of 2 whereas the atomic integer has been incremented to the thousands.
The text was updated successfully, but these errors were encountered: