Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Singleton
- class PostRepositoryImpl @Inject constructor(
- private val cache: PostCache,
- private val remote: PostRemote,
- private val mapper: PostMapper) : PostRepository {
- override fun get(refresh: Boolean): Single<List<Post>> = when (refresh) {
- true -> remote.getPosts().flatMap { set(it) }.map { mapper.mapToDomain(it) }
- false -> cache.load().map { mapper.mapToDomain(it) }.onErrorResumeNext { get(true) }
- }
- private fun set(list: List<PostEntity>) = cache.save(list)
- }
Add Comment
Please, Sign In to add comment