How it works ?
Here you can find a detailed explanation of how Livebox works and how you can customize it.
// Create validators
Validator<UsersRes> persistentDiskValidator = (key, item) -> Objects.nonNull(item) && !item.getItems().isEmpty();
// 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.minutes(2))
.addSource(Sources.DISK_PERSISTENT, persistentDiskValidator)
.addConverter(UsersRes.class, usersRes -> Optional.of(Users.fromUsersRes(usersRes)))
.retryOnFailure()
.build();
// Using scoped feature, this uses Uber's autodispose
usersBox.scoped(AndroidLifecycleScopeProvider.from(this))
.subscribe(
users -> Log.d(TAG, "Users: " + users),
Throwable::printStackTrace
);
Flow diagram

Last updated