Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

缓存问题[Bug]: #262

Open
zzzzziv opened this issue Nov 1, 2024 · 2 comments
Open

缓存问题[Bug]: #262

zzzzziv opened this issue Nov 1, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@zzzzziv
Copy link

zzzzziv commented Nov 1, 2024

框架版本【必填】

12.8

问题描述【必填】

同步请求,使用CacheMode.USE_CACHE_FIRST的缓存策略,不会写入缓存。优先使用缓存,应该也需要写入缓存才对。
image
导致,会报两个错误,一个是请求成功,解析失败,一个是请求失败。但是最终还是获取了数据,也就是说使用了CacheMode.USE_CACHE_FIRST缓存策略,一共调用了3次回调,其中一次是成功的。
image

复现步骤【必填】

1.把缓存策略改成CacheMode.USE_CACHE_FIRST
2.然后使用同步请求

是否必现【必填】

项目 targetSdkVersion【必填】

34

出现问题的手机信息【必填】

原生安卓

出现问题的安卓版本【必填】

Android12

问题信息的来源渠道【必填】

自己遇到的

是部分机型还是所有机型都会出现【必答】

框架最新的版本是否存在这个问题【必答】

框架文档是否提及了该问题【必答】

是否已经查阅框架文档但还未能解决的【必答】

issue 列表中是否有人曾提过类似的问题【必答】

是否已经搜索过了 issue 列表但还未能解决的【必答】

是否可以通过 Demo 来复现该问题【必答】

提供报错堆栈

2024-11-01 18:22:00.262 14431-14463 EasyHttp A...rl@4370c26 com.xinyu.waterfall                  E  null
                                                                                                    java.lang.NullPointerException
                                                                                                    	at java.util.Objects.requireNonNull(Objects.java:220)
                                                                                                    	at com.google.gson.reflect.TypeToken.<init>(TypeToken.java:80)
                                                                                                    	at com.google.gson.reflect.TypeToken.get(TypeToken.java:314)
                                                                                                    	at com.google.gson.Gson.fromJson(Gson.java:1014)
                                                                                                    	at com.xinyu.repository.http.common.RequestHandler.requestSuccess(RequestHandler.java:118)
                                                                                                    	at com.hjq.http.callback.NormalCallback.onHttpResponse(NormalCallback.java:106)
                                                                                                    	at com.hjq.http.callback.BaseCallback.onResponse(BaseCallback.java:72)
                                                                                                    	at okhttp3.RealCall$AsyncCall.execute(RealCall.java:203)
                                                                                                    	at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
                                                                                                    	at java.lang.Thread.run(Thread.java:920)
2024-11-01 18:22:00.264 14431-14463 EasyHttp A...rl@4370c26 com.xinyu.waterfall                  E  null
                                                                                                    com.hjq.http.exception.HttpException
                                                                                                    	at com.xinyu.repository.http.common.RequestHandler.requestFail(RequestHandler.java:178)
                                                                                                    	at com.hjq.http.callback.NormalCallback.onHttpFailure(NormalCallback.java:145)
                                                                                                    	at com.hjq.http.callback.BaseCallback.onResponse(BaseCallback.java:75)
                                                                                                    	at okhttp3.RealCall$AsyncCall.execute(RealCall.java:203)
                                                                                                    	at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
                                                                                                    	at java.lang.Thread.run(Thread.java:920)
2024-11-01 18:22:01.250 14431-14532 ion                     com.xinyu.waterfall                  E  ioctl c0044901 failed with code -1: Invalid argument

提供截图或视频

image

提供解决方案

Response response = this.mCallProxy.execute();
cacheResult = this.mRequestHandler.requestSuccess(this, response, reflectType);
if (cacheMode == CacheMode.USE_CACHE_ONLY || cacheMode == CacheMode.USE_CACHE_AFTER_FAILURE ||cacheMode==CacheMode.USE_CACHE_FIRST) {
    try {
        boolean writeCacheResult = this.mRequestHandler.writeCache(this, response, cacheResult);
        EasyLog.printLog(this, "WriteCache result:" + writeCacheResult);
    } catch (Throwable var8) {
        EasyLog.printLog(this, "WriteCache error");
        EasyLog.printThrowable(this, var8);
    }
}
@zzzzziv zzzzziv added the bug Something isn't working label Nov 1, 2024
@zzzzziv zzzzziv changed the title [Bug]: 缓存问题[Bug]: Nov 1, 2024
@zzzzziv
Copy link
Author

zzzzziv commented Nov 1, 2024

解析错误是因为RequestHandler回调中的Type属性为null,请求方法,已经使用ResponseClass传入了相应的类型,且最后都有一次成功请求,在同步的回调中,也执行了一次方法。但是RequestHandler被调用了3次,且有两次失败,最终不影响业务的实现,但是报错了,就想修复。

@getActivity
Copy link
Owner

问题修复了,更新到 13.0 版本再试一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants