From 61e537aa982868ab461f3f9a9be17179aa71b042 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 1 Aug 2022 14:43:58 +0800 Subject: [PATCH] android: optimize debugging do not cache assets file from local dir --- .../pub/doric/devkit/DoricDevAssetsLoader.java | 4 ++-- .../pub/doric/resource/DoricRemoteResource.java | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDevAssetsLoader.java b/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDevAssetsLoader.java index fb53ba1f..c57ffd16 100644 --- a/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDevAssetsLoader.java +++ b/doric-android/devkit/src/main/java/pub/doric/devkit/DoricDevAssetsLoader.java @@ -33,8 +33,8 @@ public class DoricDevAssetsLoader extends DoricAssetsLoader { return new DoricRemoteResource(doricContext, String.format("http://%s:7778/assets/%s", DoricDev.getInstance().getIP(), - identifier - )); + identifier), + false); } return super.load(doricContext, identifier); } diff --git a/doric-android/doric/src/main/java/pub/doric/resource/DoricRemoteResource.java b/doric-android/doric/src/main/java/pub/doric/resource/DoricRemoteResource.java index 98f4f037..e0954beb 100644 --- a/doric-android/doric/src/main/java/pub/doric/resource/DoricRemoteResource.java +++ b/doric-android/doric/src/main/java/pub/doric/resource/DoricRemoteResource.java @@ -16,7 +16,9 @@ package pub.doric.resource; import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.load.DataSource; +import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.target.Target; @@ -35,15 +37,26 @@ import pub.doric.async.AsyncResult; * @CreateDate: 2021/10/20 */ public class DoricRemoteResource extends DoricResource { + private final boolean needCache; + + public DoricRemoteResource(DoricContext doricContext, String identifier, boolean needCache) { + super(doricContext, identifier); + this.needCache = needCache; + } public DoricRemoteResource(DoricContext doricContext, String identifier) { - super(doricContext, identifier); + this(doricContext, identifier, true); } @Override public AsyncResult fetchRaw() { final AsyncResult result = new AsyncResult<>(); - Glide.with(doricContext.getContext()).download(identifier) + RequestBuilder requestBuilder = Glide.with(doricContext.getContext()).download(identifier); + if (!this.needCache) { + requestBuilder = requestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE) + .skipMemoryCache(true); + } + requestBuilder .listener(new RequestListener() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {