WaterfallCache implements Cache { @Override public Observable<Boolean> contains(final String key) { if (memoryCache != null) { Object memoryValue = memoryCache.get(key); if (memoryValue != null) { return Observable.just(true).compose(applySchedulers()); } } return achieveOnce(false, cache -> cache.contains(key), value -> value) .flatMap(resultWrapper -> { if (resultWrapper.result && resultWrapper.hitCacheIdx > 0) { return get(key, Object.class).map(o -> true); } return Observable.just(resultWrapper.result); }); } private  WaterfallCache(List<RxCache> caches, Scheduler observeOnScheduler, int inlineMemoryCacheSize); @Override Observable<T> get(final String key, final Type typeOfT); @Override Observable<Boolean> put(final String key, final Object object); @Override Observable<Boolean> contains(final String key); @Override Observable<Boolean> remove(final String key); @Override Observable<Boolean> clear(); @Override void getAsync(String key, Type typeOfT, WaterfallGetCallback<T> callback); @Override void putAsync(String key, Object object, WaterfallCallback callback); @Override void containsAsync(String key, WaterfallGetCallback<Boolean> callback); @Override void removeAsync(String key, WaterfallCallback callback); @Override void clearAsync(WaterfallCallback callback); void setObserveOnScheduler(Scheduler scheduler); static Builder builder();  }
@Test public void testContainsLevel1() throws Exception { String key = "TEST_KEY"; when(cache1.contains(eq(key))).thenReturn(Observable.just(true)); Observable<Boolean> observable = waterfallCache.contains(key); ObservableTestUtils.testObservable(observable, Assert::assertTrue); verify(cache1).contains(eq(key)); verifyZeroInteractions(cache2); }
@Test public void testContainsNoValue() throws Exception { String key = "TEST_KEY"; when(cache1.contains(eq(key))).thenReturn(Observable.just(false)); when(cache2.contains(eq(key))).thenReturn(Observable.just(false)); Observable<Boolean> observable = waterfallCache.contains(key); ObservableTestUtils.testObservable(observable, Assert::assertFalse); verify(cache1).contains(eq(key)); verify(cache2).contains(eq(key)); }