同花顺previous改造响应 [英] Flush previous Retrofit responses

查看:160
本文介绍了同花顺previous改造响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用我需要下载的元数据从一个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.

我已经看过<一个href=\"https://github.com/swankjesse/android-http-examples/blob/master/http/src/main/java/com/publicobject/http/cache/OkHttpExample.java\"相对=nofollow>这个例子和编辑以下行使用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);

这篇关于同花顺previous改造响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆