iagocanalejas / retrocache

This library provides an easy way for configure retrofit for use a 2 layer cache (RAM and Disk)
Apache License 2.0
35 stars 7 forks source link

cache not working #5

Closed asadi110 closed 7 years ago

asadi110 commented 7 years ago

hi, thanks for your easy and clean library . I configured my project according to your guide, but cache is not working and services are called in online mode and no response is backed in offline mode. and no error occurred. 1: @FormUrlEncoded @POST("rest/") CachedCall<GeneralResult> getAvatar( @Field("method") ServiceType method, @Field("user_name") String userName); 2: DualCache<String, byte[]> mCache = RetroCache.getDualCache(MyApplication.context,BuildConfig.VERSION_CODE); 3: mRetrofitClient = new Retrofit.Builder() .baseUrl(ClientConfigs.REST_API_BASE_URL) .client(client) .addConverterFactory(GsonConverterFactory.create(gson)) .addCallAdapterFactory(new CachedCallFactory(mCache)) .build(); 4: CachedCall<GeneralResult> call = tService.getAvatar(ServiceType.GetAvatar, pref.getStudyCode());

        call.enqueue(new Callback<GeneralResult<String>>() {

            @Override
            public void onResponse(Call<GeneralResult<String>> call, Response<GeneralResult<String>> response) {

                if (response.isSuccessful() && response.body().getStatus()==0) {

... pleas help me.tnx

iagocanalejas commented 7 years ago

Sorry for late answer, just disconnected the weekend.

Your method is a @POST method, if i have understood your code correctly. Cache only works for @GET.

Why would you want to cache a POST if i might know?

asadi110 commented 7 years ago

Thanks for your response. Although it's not right ,all web services are implemented as @POST methods in server side and data will be backed in response of @POST methods.

iagocanalejas commented 7 years ago

I don't think this is a proper behaviour but you can implement it for your use just changing/adding the behaviour in the CachedCallImpl class. Also i don't know if the behavior will work correctly.

asadi110 commented 7 years ago

Thanks.