Search in sources :

Example 1 with EvictDynamicKey

use of io.rx_cache2.EvictDynamicKey in project 91Pop by DanteAndroid.

the class AppApiHelper method loadPigAvListByCategory.

@Override
public Observable<List<PigAv>> loadPigAvListByCategory(String category, boolean pullToRefresh) {
    DynamicKey dynamicKey = new DynamicKey(category);
    EvictDynamicKey evictDynamicKey = new EvictDynamicKey(pullToRefresh);
    if ("index".equals(category)) {
        return action(cacheProviders.cacheWithLimitTime(pigAvServiceApi.pigAvVideoList(addressHelper.getPigAvAddress()), dynamicKey, evictDynamicKey));
    } else {
        return action(cacheProviders.cacheWithLimitTime(pigAvServiceApi.pigAvVideoList(addressHelper.getPigAvAddress() + category + "av線上看"), dynamicKey, evictDynamicKey));
    }
}
Also used : EvictDynamicKey(io.rx_cache2.EvictDynamicKey) DynamicKey(io.rx_cache2.DynamicKey) EvictDynamicKey(io.rx_cache2.EvictDynamicKey)

Example 2 with EvictDynamicKey

use of io.rx_cache2.EvictDynamicKey in project 91Pop by DanteAndroid.

the class AppApiHelper method loadPorn91MyFavoriteVideos.

@Override
public Observable<BaseResult<List<UnLimit91PornItem>>> loadPorn91MyFavoriteVideos(String userName, int page, boolean cleanCache) {
    Observable<String> favoriteObservable = noLimit91PornServiceApi.myFavoriteVideo(page, HeaderUtils.getIndexHeader(addressHelper));
    DynamicKeyGroup dynamicKeyGroup = new DynamicKeyGroup(userName, page);
    EvictDynamicKey evictDynamicKey = new EvictDynamicKey(cleanCache);
    return cacheProviders.getFavorite(favoriteObservable, dynamicKeyGroup, evictDynamicKey).map(new Function<Reply<String>, String>() {

        @Override
        public String apply(Reply<String> responseBody) throws Exception {
            return responseBody.getData();
        }
    }).map(new Function<String, BaseResult<List<UnLimit91PornItem>>>() {

        @Override
        public BaseResult<List<UnLimit91PornItem>> apply(String s) throws Exception {
            return Parse91PronVideo.parseMyFavorite(s);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) BaseResult(com.dante.data.model.BaseResult) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Reply(io.rx_cache2.Reply) EvictDynamicKeyGroup(io.rx_cache2.EvictDynamicKeyGroup) DynamicKeyGroup(io.rx_cache2.DynamicKeyGroup) UnLimit91PornItem(com.dante.data.model.UnLimit91PornItem) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

Example 3 with EvictDynamicKey

use of io.rx_cache2.EvictDynamicKey in project RxCache by VictorAlbertos.

the class ProxyTranslatorTest method When_Evict_Cache_Dynamic_Key_Evict.

@Test
public void When_Evict_Cache_Dynamic_Key_Evict() throws NoSuchMethodException {
    final String dynamicKey = "aDynamicKey";
    Method mockMethod = io.rx_cache2.internal.ProvidersRxCache.class.getDeclaredMethod("getMocksDynamicKeyEvictPage", Observable.class, DynamicKey.class, EvictDynamicKey.class);
    Object[] dataMethodEvict = { Observable.just(new Object[] {}), new DynamicKey(dynamicKey), new EvictDynamicKey(true) };
    ConfigProvider configProvider = proxyTranslatorUT.processMethod(mockMethod, dataMethodEvict);
    EvictDynamicKey evictDynamicKey = (EvictDynamicKey) configProvider.evictProvider();
    assertThat(configProvider.getDynamicKey(), is(dynamicKey));
    assertThat(evictDynamicKey.evict(), is(true));
    Object[] dataMethodNoEvict = { Observable.just(new Object[] {}), new DynamicKey(dynamicKey), new EvictDynamicKey(false) };
    configProvider = proxyTranslatorUT.processMethod(mockMethod, dataMethodNoEvict);
    evictDynamicKey = (EvictDynamicKey) configProvider.evictProvider();
    assertThat(configProvider.getDynamicKey(), is(dynamicKey));
    assertThat(evictDynamicKey.evict(), is(false));
}
Also used : ConfigProvider(io.rx_cache2.ConfigProvider) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Method(java.lang.reflect.Method) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) DynamicKey(io.rx_cache2.DynamicKey) Test(org.junit.Test)

Example 4 with EvictDynamicKey

use of io.rx_cache2.EvictDynamicKey in project RxCache by VictorAlbertos.

the class ProxyTranslatorTest method When_Use_Evict_Dynamic_Key_Providing_Dynamic_Key_Not_Throw_Exception.

@Test
public void When_Use_Evict_Dynamic_Key_Providing_Dynamic_Key_Not_Throw_Exception() throws NoSuchMethodException {
    Method mockMethod = io.rx_cache2.internal.ProvidersRxCache.class.getDeclaredMethod("getMockEvictDynamicKeyProvidingDynamicKey", Observable.class, DynamicKey.class, EvictDynamicKey.class);
    Object[] data = { Observable.just(new Object[] {}), new DynamicKey("1"), new EvictDynamicKey(true) };
    proxyTranslatorUT.processMethod(mockMethod, data);
}
Also used : EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Method(java.lang.reflect.Method) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) DynamicKey(io.rx_cache2.DynamicKey) Test(org.junit.Test)

Example 5 with EvictDynamicKey

use of io.rx_cache2.EvictDynamicKey in project 91Pop by DanteAndroid.

the class AppApiHelper method loadPorn91VideoUrl.

@Override
public Observable<VideoResult> loadPorn91VideoUrl(String viewKey) {
    String ip = addressHelper.getRandomIPAddress();
    Observable<String> stringObservable = noLimit91PornServiceApi.getVideoPlayPage(viewKey, ip, HeaderUtils.getIndexHeader(addressHelper));
    return cacheProviders.getVideoPlayPage(stringObservable, new DynamicKey(viewKey), new EvictDynamicKey(false)).map(new Function<Reply<String>, String>() {

        @Override
        public String apply(Reply<String> responseBodyReply) throws Exception {
            switch(responseBodyReply.getSource()) {
                case CLOUD:
                    Logger.t(TAG).d("数据来自:网络");
                    break;
                case MEMORY:
                    Logger.t(TAG).d("数据来自:内存");
                    break;
                case PERSISTENCE:
                    Logger.t(TAG).d("数据来自:磁盘缓存");
                    break;
                default:
                    break;
            }
            return responseBodyReply.getData();
        }
    }).map(new Function<String, VideoResult>() {

        @Override
        public VideoResult apply(String s) throws Exception {
            return Parse91PronVideo.parseVideoPlayUrl(s);
        }
    });
}
Also used : Function(io.reactivex.functions.Function) VideoResult(com.dante.data.model.VideoResult) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) Reply(io.rx_cache2.Reply) DynamicKey(io.rx_cache2.DynamicKey) EvictDynamicKey(io.rx_cache2.EvictDynamicKey) FavoriteException(com.dante.exception.FavoriteException) MessageException(com.dante.exception.MessageException)

Aggregations

EvictDynamicKey (io.rx_cache2.EvictDynamicKey)11 Reply (io.rx_cache2.Reply)7 FavoriteException (com.dante.exception.FavoriteException)6 MessageException (com.dante.exception.MessageException)6 Function (io.reactivex.functions.Function)6 DynamicKey (io.rx_cache2.DynamicKey)6 BaseResult (com.dante.data.model.BaseResult)4 UnLimit91PornItem (com.dante.data.model.UnLimit91PornItem)4 DynamicKeyGroup (io.rx_cache2.DynamicKeyGroup)4 EvictDynamicKeyGroup (io.rx_cache2.EvictDynamicKeyGroup)4 Test (org.junit.Test)4 Method (java.lang.reflect.Method)3 PigAvVideo (com.dante.data.model.PigAvVideo)1 VideoResult (com.dante.data.model.VideoResult)1 ConfigProvider (io.rx_cache2.ConfigProvider)1