Skip to content

Instantly share code, notes, and snippets.

View mohanmanu484's full-sized avatar

Mohan mohanmanu484

  • Banglore
View GitHub Profile
@mohanmanu484
mohanmanu484 / ApiManager.java
Created May 26, 2017 05:31 — forked from marcelpinto/ApiManager.java
Cache RxJava observables on Android approach to reuse and avoid multiple calls.
private ObservableManager obsManager = new ObservableManager(EventBus.getDefault());
@Override
public Subscription getStores() {
// Get the observable if exists and is not too old
Observable<StoresList> observable = obsManager.get(ObservableManager.Types.STORES);
if (observable == null) {
// If is null create it and us cache to keep it in memeroy
observable = api.getStoresList()
.compose(applySchedulers(api.getStoresList()))