From ddc6b60d48ff357b59142e5ac268dee047fffd6e Mon Sep 17 00:00:00 2001 From: yale8848 Date: Thu, 26 Oct 2017 16:40:12 +0800 Subject: [PATCH] fix 304 from ram cache --- README.md | 2 +- README_EN.md | 2 +- cachewebviewlib/config/bintray.gradle | 2 +- .../cachewebviewlib/ResourseInputStream.java | 4 ++-- .../android/cachewebviewlib/WebViewCache.java | 19 +++++++++---------- gradle.properties | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 96e625d..35a8618 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ### 引入库 ``` -compile 'ren.yale.android:cachewebviewlib:1.1.2' +compile 'ren.yale.android:cachewebviewlib:1.1.3' ``` ### 修改代码 diff --git a/README_EN.md b/README_EN.md index 4737ea6..c4b46ca 100644 --- a/README_EN.md +++ b/README_EN.md @@ -8,7 +8,7 @@ ### use lib ``` -compile 'ren.yale.android:cachewebviewlib:1.1.2' +compile 'ren.yale.android:cachewebviewlib:1.1.3' ``` ### Change code diff --git a/cachewebviewlib/config/bintray.gradle b/cachewebviewlib/config/bintray.gradle index 8645d6b..66803ca 100644 --- a/cachewebviewlib/config/bintray.gradle +++ b/cachewebviewlib/config/bintray.gradle @@ -4,7 +4,7 @@ apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.jfrog.bintray' -version = '1.1.2' +version = '1.1.3' repositories { jcenter() diff --git a/cachewebviewlib/src/main/java/ren/yale/android/cachewebviewlib/ResourseInputStream.java b/cachewebviewlib/src/main/java/ren/yale/android/cachewebviewlib/ResourseInputStream.java index 65795b4..2c04a98 100644 --- a/cachewebviewlib/src/main/java/ren/yale/android/cachewebviewlib/ResourseInputStream.java +++ b/cachewebviewlib/src/main/java/ren/yale/android/cachewebviewlib/ResourseInputStream.java @@ -126,7 +126,7 @@ public void close() throws IOException { ram.setAllHttpFlag(allFlag); ram.setInputStreamSize(buffer.length); mLruCache.put(WebViewCache.getKey(mUrl),ram); - CacheWebViewLog.d(mUrl +" ram cached"); + CacheWebViewLog.d("ram cached "+mUrl); }catch (Exception e){ } } @@ -139,7 +139,7 @@ public void close() throws IOException { mOutputStreamProperty.close(); mOutputStream.close(); mOutputStreamAllProperty.close(); - CacheWebViewLog.d(mUrl +" disk cached"); + CacheWebViewLog.d("disk cached "+mUrl); }else if (mEditorContent!=null){ mEditorContent.abort(); } diff --git a/cachewebviewlib/src/main/java/ren/yale/android/cachewebviewlib/WebViewCache.java b/cachewebviewlib/src/main/java/ren/yale/android/cachewebviewlib/WebViewCache.java index f785229..b05abd8 100644 --- a/cachewebviewlib/src/main/java/ren/yale/android/cachewebviewlib/WebViewCache.java +++ b/cachewebviewlib/src/main/java/ren/yale/android/cachewebviewlib/WebViewCache.java @@ -249,9 +249,10 @@ public InputStream httpRequest(WebView view,String url) { resourseInputStream = new ResourseInputStream(url,httpURLConnection.getInputStream(), getEditor(getKey(url)),remote,mLruCache); }else{ - CacheWebViewLog.d(url+" 304 from cache"); - resourseInputStream = new ResourseInputStream(url,inputStream, - null,remote,mLruCache); + CacheWebViewLog.d("304 from cache "+url); + return inputStream; + //resourseInputStream = new ResourseInputStream(url,inputStream, + // null,remote,mLruCache); } return resourseInputStream; } @@ -362,7 +363,7 @@ public CacheStatus getCacheFile(String url){ private InputStream getCacheInputStream(String url){ InputStream inputStream = getRamCache(url); if (inputStream!=null){ - CacheWebViewLog.d(url +": from ram cache"); + CacheWebViewLog.d("from ram cache "+url); return inputStream; } try { @@ -375,7 +376,7 @@ private InputStream getCacheInputStream(String url){ e.printStackTrace(); } if (inputStream!=null){ - CacheWebViewLog.d(url +": from disk cache"); + CacheWebViewLog.d("from disk cache "+url); } return inputStream; } @@ -392,7 +393,7 @@ public WebResourceResponse getWebResourceResponse(WebView view,String url, if (!url.startsWith("http")){ return null; } - CacheWebViewLog.d(url +" visit"); + CacheWebViewLog.d("visit "+url); if (cacheInterceptor!=null){ if (!cacheInterceptor.canCache(url)){ @@ -448,13 +449,12 @@ public WebResourceResponse getWebResourceResponse(WebView view,String url, inputStreamUtils.setEncodeBuffer(mEncodeBufferSize); long start = System.currentTimeMillis(); InputStream copyInputStream = inputStreamUtils.copy(); - CacheWebViewLog.d(url+" get encoding timecost: "+(System.currentTimeMillis()-start)); if (copyInputStream == null){ return null; } resourseInputStream.setInnerInputStream(copyInputStream); encode = inputStreamUtils.getEncoding(); - CacheWebViewLog.d(encode+" "+ url); + CacheWebViewLog.d(encode+" "+"get encoding timecost: "+(System.currentTimeMillis()-start)+ " "+url); } WebResourceResponse webResourceResponse= new WebResourceResponse(mimeType,encode ,inputStream); @@ -469,13 +469,12 @@ public WebResourceResponse getWebResourceResponse(WebView view,String url, inputStreamUtils.setEncodeBuffer(mEncodeBufferSize); long start = System.currentTimeMillis(); InputStream copyInputStream = inputStreamUtils.copy(); - CacheWebViewLog.d(url+" get encoding timecost: "+(System.currentTimeMillis()-start)); if (copyInputStream == null){ return null; } inputStream = copyInputStream; encode = inputStreamUtils.getEncoding(); - CacheWebViewLog.d(encode+" "+ url); + CacheWebViewLog.d(encode+" "+" get encoding timecost: "+(System.currentTimeMillis()-start)+ " "+url); } Map map = getAllHttpHeaders(url); WebResourceResponse webResourceResponse= new WebResourceResponse(mimeType,encode,inputStream); diff --git a/gradle.properties b/gradle.properties index 3fa7b5e..64d5797 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,4 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -#org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_92 +org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_92