Skip to content

Instantly share code, notes, and snippets.

@justdoit0823
Last active February 16, 2019 09:48
Show Gist options
  • Save justdoit0823/2bdc983d0ed085ec136c903ece9405ef to your computer and use it in GitHub Desktop.
Save justdoit0823/2bdc983d0ed085ec136c903ece9405ef to your computer and use it in GitHub Desktop.
Guava LocalLoadingCache refresh process.

LocalLoadingCache.get

  • living value exists

When it's time to refresh, competing for the asynchronous loading with the specified loader. If the loading thread is immediately done, returning the new value. Otherwise returning the current living value. Finally, the cache will be updated with the loading value.

  • non living value exists

If there is already a loading thread, waiting the loading value. Otherwise competing for the synchronous loading. Finally, returning the new loaded value and updating the cache.

The specified key has only a single loading thread during the loading peroid

Synchronous versus Asynchronous

The loading works as the following. When the old value is not null, invoking the specified loader's reload method with it. Otherwise invoking the load method.

  • loadSync

Start loading, then indefinitely waiting the new loaded value.

  • loadAsync

Start loading, but returning the loading future without wait.

The default reload method invokes the load method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment