From e6eb7a043092f7d2c297f7557dae998017fff9b3 Mon Sep 17 00:00:00 2001 From: open-android Date: Fri, 16 Dec 2016 17:38:08 +0800 Subject: [PATCH] update cache bug --- .../java/com/itheima/retrofitutils/HttpHelper.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/retrofitutils/src/main/java/com/itheima/retrofitutils/HttpHelper.java b/retrofitutils/src/main/java/com/itheima/retrofitutils/HttpHelper.java index e82350f..61501ba 100644 --- a/retrofitutils/src/main/java/com/itheima/retrofitutils/HttpHelper.java +++ b/retrofitutils/src/main/java/com/itheima/retrofitutils/HttpHelper.java @@ -73,6 +73,13 @@ public static String getBaseUrl() { } private HttpHelper() { + //缓存路径 + mCacheFile = new File(ItheimaHttp.getContext().getCacheDir().getAbsolutePath() + File.separator + "retrofit2_http_cache"); + //判断缓存路径是否存在 + if (!mCacheFile.exists() && !mCacheFile.isDirectory()) { + mCacheFile.mkdir(); + } + OkHttpClient okHttpClient = createOkhttpAndCache(); mRetrofit = new Retrofit.Builder() .baseUrl(sBaseUrl) @@ -80,12 +87,6 @@ private HttpHelper() { .addConverterFactory(StringConverterFactory.create()) //.addConverterFactory(GsonConverterFactory.create()) .build(); - //缓存路径 - mCacheFile = new File(ItheimaHttp.getContext().getCacheDir().getAbsolutePath() + File.separator + "retrofit2_http_cache"); - //判断缓存路径是否存在 - if (!mCacheFile.exists() && !mCacheFile.isDirectory()) { - mCacheFile.mkdir(); - } }