-
Notifications
You must be signed in to change notification settings - Fork 120
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
Support concurent calls. #159
Comments
@crakjie there is a problem with caching |
@aliaksandrKachurka, @crakjie In caffeine you can accomplish this by doing However under the hood scalacache-caffeine uses cache.getIfPresent which is racy. You can work around it by doing this in scalacache.
This results in a single increment of our atomic integer at any concurrency. while this
Will be incremented a number of times equal to what your level of parallelism is. If the scalacache-caffeine would be updated to use get(key, k -> v) instead of getIfPresent(key) then this issue should be resolved. |
Related article: https://softwaremill.com/race-condition-cache-guava-caffeine/ |
Actually, call multiple time the same key concurrently can make the cached block to be computed multiple time event for futures blocks.
So there is 1000 call to the block, which says, the cache had no effect.
Some Scala implementation resolves this issue by caching the Future.
Like that every successive call returns a future which can wait for the cache caller.
I had also try with a Cache of Future
same result, but if the mode is sync it's work.
edit :
I have made some try, a cache with a fixed F aka
Cache[V, F[_]]
may resolve the problem.where the mode is given when the cache is instantiated.
The text was updated successfully, but these errors were encountered: