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

Question about cache refresh #465

Closed
kimmikimmi opened this issue Oct 16, 2020 · 1 comment
Closed

Question about cache refresh #465

kimmikimmi opened this issue Oct 16, 2020 · 1 comment

Comments

@kimmikimmi
Copy link

Is there best practice to refresh synchronously?
refresh asynchronously is good in most cases, but I have some cases it needs to block to return until refresh is done.

@ben-manes
Copy link
Owner

ben-manes commented Oct 16, 2020

You might want #143, where LoadingCache#refresh would return CompletableFuture. Unfortunately that requires a major version bump since it changes the interface signature.

You might instead use asMap().computeIfPresent to perform the call synchronously. That would block other writers to that hashbin (~ per entry) but not block readers.

Another option is to use Caffeine.executor(Runnable::run) to perform any async logic directly on the caller's thread. In most cases this is okay, but if your code is expensive then it can add latency (e.g. some readers are penalized by performing the work).

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

2 participants