Skip to content

Commit

Permalink
fix 304 from ram cache
Browse files Browse the repository at this point in the history
  • Loading branch information
yale8848 committed Oct 26, 2017
1 parent d5de9a9 commit ddc6b60
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
### 引入库

```
compile 'ren.yale.android:cachewebviewlib:1.1.2'
compile 'ren.yale.android:cachewebviewlib:1.1.3'
```

### 修改代码
Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
### use lib

```
compile 'ren.yale.android:cachewebviewlib:1.1.2'
compile 'ren.yale.android:cachewebviewlib:1.1.3'
```

### Change code
Expand Down
2 changes: 1 addition & 1 deletion cachewebviewlib/config/bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
}
}
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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)){
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ddc6b60

Please sign in to comment.