Skip to content
This repository has been archived by the owner on Aug 9, 2020. It is now read-only.

如何做到RxCache 先加缓存后请求? #135

Open
KomoriWu opened this issue Dec 14, 2018 · 1 comment
Open

如何做到RxCache 先加缓存后请求? #135

KomoriWu opened this issue Dec 14, 2018 · 1 comment

Comments

@KomoriWu
Copy link

有网络时,先显示缓存的数据,然后再走网络,更新页面和缓存。
thanks

@nemo-ex
Copy link

nemo-ex commented Apr 29, 2019

这样可以吗?

fun loadNews(): Observable<List<News>> {
    return Observable.create { emitter ->
        var result = mAppCache.newsList(mAppService.newsList(), EvictProvider(false)).blockingFirst()
        emitter.onNext(result.data)
        if (result.source != Source.CLOUD) {
            result = mAppCache.newsList(mAppService.newsList(), EvictProvider(true)).blockingFirst()
            emitter.onNext(result.data)  
        }
        emitter.onComplete()
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants