同花顺previous改造响应
在我的Android应用我需要下载的元数据从一个XML API的一些文件。
我使用的改造来处理,我已经实现了异步那些在回调我解析XML的请求,并保存在一个文件,我需要的数据。
In my Android app I need to download metadata for some files from a XML API. I am using RetroFit to handle the requests that I've implemented as asynchronous ones, in the Callback I parse the XML and save in a file the data I need.
当我需要获取信息的许多文件,我得到的OutOfMemoryError
和分析与MAT堆,我发现了previous反应的XML主体仍然存在。有没有什么办法来强制应用程序以刷新已经使用XML?
When I need to get info for many files, I get OutOfMemoryError
and analyzing the heap with MAT, I discovered that XML body of previous responses is still there. Is there any way to force the app to flush the already used XML?
我想我找到了解决办法:
I think I found a solution:
默认情况下, OkHttpClient
使用内存高速缓存实施的Htt presponseCache
,切换到磁盘实现我能没有得到任何内存不足
错误运行10000请求。
By default, the OkHttpClient
uses a memory cache implementation for HttpResponseCache
, switching to a disk implementation I was able to run 10000 requests without getting any OutOfMemory
error.
我已经看过这个例子和编辑以下行使用Android内部存储:
I have looked at this example and edited the following lines to use Android internal storage:
File cacheDir = new File(System.getProperty("java.io.tmpdir"), "okhttp-cache");
cache = new HttpResponseCache(cacheDir, 10L * 1024 * 1024);
okHttpClient = new OkHttpClient();
okHttpClient.setResponseCache(cache);