Comments (6)
Don't save the object BaseResponse
, instead, use map
operator to transform it to UserBasicInfoResponse
prior to calling RxCache.
Observable<UserBasicInfoResponse> oUser = userBasicInfoResponseObservable
.map(userBasicInfoResponse -> userBasicInfoResponse.data);
rxProviders.loadUserBasicInfo(oUser , new DynamicKey(1) , new EvictProvider(false));
from rxcache.
Thinks so much for your quick reply!
but I still have some confused ,since data from net is Observable<BaseResponse<UserBasicInfoResponse>>
,how can I save UserBasicInfoResponse
instead of BaseResponse<UserBasicInfoResponse>
, do you give me some detail advices ?
thanks!
my core code about it as below
This is the core method:
@Override
public Observable<UserBasicInfo> getUserBasicInfo(final boolean isUpdateNow) {
return mLoginUserCache.get()
.flatMap(new Func1<User, Observable<Reply<BaseResponse<UserBasicInfoResponse>>>>() {
@Override
public Observable<Reply<BaseResponse<UserBasicInfoResponse>>> call(User user) {
return mUserCacheProviders.loadUserBasicInfo(mUserApi.loadUserBasicInfo(user.getUserId()), new DynamicKey(user.getUserId()), new EvictProvider(isUpdateNow));
}
}).flatMap(new Func1<Reply<BaseResponse<UserBasicInfoResponse>>, Observable<UserBasicInfo>>() {
@Override
public Observable<UserBasicInfo> call(Reply<BaseResponse<UserBasicInfoResponse>> baseResponseReply) {
if (null == baseResponseReply || null == baseResponseReply.getData()) {
return Observable.empty();
}
BaseResponse<UserBasicInfoResponse> userBasicInfoResponseBaseResponse = baseResponseReply.getData();
if (!userBasicInfoResponseBaseResponse.isSuccess()) {
return Observable.error(new ServerResponseException(userBasicInfoResponseBaseResponse.getMsg()));
}
ThinkcooLog.d("---->", userBasicInfoResponseBaseResponse.toString());
UserBasicInfoResponse userBasicInfoResponse = userBasicInfoResponseBaseResponse.getData();
return Observable.just(UserBasicInfo.fromServerResponse(userBasicInfoResponse, mServerDataConverter));
}
});
}
This is the net API
@POST("personalinfor.json")
Observable<BaseResponse<UserBasicInfoResponse>> loadUserBasicInfo(@Query("userId") String userId);
This is the cache interface method
@LifeCache(duration =5, timeUnit = TimeUnit.SECONDS)
Observable<Reply<BaseResponse<UserBasicInfoResponse>>> loadUserBasicInfo(Observable<BaseResponse<UserBasicInfoResponse>> userBasicInfoResponseObservable
, DynamicKey userId , EvictProvider evictProvider);
from rxcache.
The endpoint should be
@LifeCache(duration =5, timeUnit = TimeUnit.SECONDS)
Observable<UserBasicInfoResponse> loadUserBasicInfo(Observable<UserBasicInfoResponse> userBasicInfoResponseObservable
, DynamicKey userId , EvictProvider evictProvider);
And you just need to apply the map operator to transform the data. I suggest to you to learn a little more rxjava before attempting to use RxCache, or any reactive library for that matters. ;)
from rxcache.
OK,thank you so much!
from rxcache.
but if i want to save just baseResponse, how can i do @VictorAlbertos
from rxcache.
this is my method to avoid use BaseResponse<T>
@VictorAlbertos help me that whether this can sovle problem
from rxcache.
Related Issues (20)
- There is no option to clean the cache. HOT 3
- java.util.ConcurrentModificationException
- json转换AjaxResult<List<T>>这种类型会报下面的错 HOT 10
- java.lang.NullPointerException: The mapper function returned a null value. HOT 1
- Clearing the cache does not automatically fetch the latest
- EviceProvider doesnt work HOT 2
- How to make RxCache silently fail if no persisted data and no source data?
- No data saved in PERSISTENCE HOT 7
- useExpiredDataIfLoaderNotAvailable(true) issue HOT 5
- useExpiredDataIfLoaderNotAvailable(true) not work HOT 1
- 如何做到RxCache 先加缓存后请求? HOT 1
- RxCache returning only first value of an Observable stream HOT 1
- i dont‘t want to
- i don't want to use dagger and i was exclude dagger module,but there can throw exception HOT 1
- Can not read the cache when @encrypt
- 持久层无效!!! HOT 2
- Not Support FastJson?
- coroutines support
- Caching always return LinkedTreeMap, not POJO that I defined HOT 2
- 手动刷新数据不走缓存怎么做 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxcache.