Thanks, i see the pattern. It would help if the documentation is updated to reflect its usage in a ViewModel. I’m assuming the ViewModel loads the LiveData during its construction and any duplicate requests (like the one in response to orientation change) is going to get the cached result from LiveData. Any refresh logic from UI will have the ViewModel create a new instance of the LiveData (via loadUser) and hook into the logic of !isFresh().

public LiveData<Resource<User>> loadUser(final String userId) {
return new NetworkBoundResource<User,User>() {
... @Override
protected boolean shouldFetch(@Nullable User data) {
return rateLimiter.canFetch(userId) && (data == null || !isFresh(data));
}

...
}.getAsLiveData();
}
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade