Code Monkey home page Code Monkey logo

Comments (6)

VictorAlbertos avatar VictorAlbertos commented on August 19, 2024 1

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.

androidle avatar androidle commented on August 19, 2024

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.

VictorAlbertos avatar VictorAlbertos commented on August 19, 2024

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.

androidle avatar androidle commented on August 19, 2024

OK,thank you so much!

from rxcache.

guobinAndroid avatar guobinAndroid commented on August 19, 2024

but if i want to save just baseResponse, how can i do @VictorAlbertos

from rxcache.

ml-bright avatar ml-bright commented on August 19, 2024

this is my method to avoid use BaseResponse<T>

@VictorAlbertos help me that whether this can sovle problem

#73

from rxcache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.