Load from cache and refresh
Sometimes we want to display local data if available, but still hit the server to get the latest data available. Livebox comes with a refresh()
option to cover this use case.
// Builds an instance of Livebox using LiveboxBuilder class.
Livebox<UsersRes, Users> usersBox = new LiveboxBuilder<UsersRes, Users>()
.withKey("get_users")
.fetch(api::getUserList, UsersRes.class)
.addSource(Sources.MEMORY_LRU, ageValidator)
.addSource(Sources.DISK_PERSISTENT, persistentDiskValidator)
.addConverter(UsersRes.class, usersRes -> Optional.of(Users.fromUsersRes(usersRes)))
.retryOnFailure()
.refresh(true)
.build();
Last updated