Hi Brad,
Good question, we've just talked about a similar thing yesterday, check the thread before yours in Google Groups.
If it's in cache and it doesn't pick it up next time you load it, that means that the cache key is different for the two loads. EVERY parameter must match: size, decoders, transcoders, transformation, size, etc...
So if you preload with a certain size your target must have the same size. (I hope you see the emphasis on size :)
If Glide is not able to download the image (no network) and it's not in cache you should get the .error() image. That means that by adding a .listener() you should be able to find out when a cache miss happens. Check all those booleans in the method signatures of the listener interface as well.
Also you can try increasing the cache size: maybe you're preloading too much and it evicts most of them because of later ones.
Cheers
+Robi
--
You received this message because you are subscribed to the Google Groups "Glide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glidelibrary...@googlegroups.com.
To post to this group, send email to glidel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glidelibrary/49cca70b-63b3-42a0-98ba-9f244d23438c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
private class DownloadTileToCacheTask extends AsyncTask<String, Void, File> { @Override protected File doInBackground(String... params) { FutureTarget<File> future = Glide.with(getApplicationContext()) .load(params[0]) .downloadOnly(256, 256);
File file = null; try { file = future.get(); } catch (Exception e) { e.printStackTrace(); }
return file; } }
// Called by
new DownloadTileToCacheTask().execute("http://api.tiles.mapbox.com/v3/examples.map-zr0njcqy/0/0/0.png");
private void loadImageFromDiskCache() { final ImageView tileView = (ImageView)findViewById(R.id.cacheTileImageView); // Loads image from network if not found in disk cache// Glide.with(this).load(tileURL).diskCacheStrategy(DiskCacheStrategy.ALL).into(tileView); Glide.with(this).load(tileURL).diskCacheStrategy(DiskCacheStrategy.SOURCE).listener(new RequestListener<String, GlideDrawable>() { @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { Log.i(TAG, "Listener onException: " + e.toString()); return false; }
@Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { Log.i(TAG, "onResourceReady with resource = " + resource); Log.i(TAG, "onResourceReady from memory cache = " + isFromMemoryCache); return false; } }) .into(new SimpleTarget<GlideDrawable>(256, 256) { @Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { Log.i(TAG, "GlideDrawalble = '" + resource + "'"); tileView.setImageDrawable(resource.getCurrent()); } }); }
To view this discussion on the web visit https://groups.google.com/d/msgid/glidelibrary/167adadf-38ca-4d13-8df4-feafe87f1e20%40googlegroups.com.
Glide.with(activity)
.load(urlStr)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
Glide.with(activity)
.using(new StreamModelLoader<String>() {
@Override
public DataFetcher<InputStream> getResourceFetcher(String glideDrawable, int i, int i1) {
return null;
}
})
.load(urlStr)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
Hi Goofyz,
That's an interesting use of Glide! The image doesn't show up, so that's a half win, it means that it didn't use network :)
Tip: use different placeholder/fallback/error drawables while in dev. It's easier to see what's going on than "no image" for every scenario.
The other half is to get it show when cached: to find out why it doesn't turn on logging for the Engine tag and check the cache key, they must match: https://github.com/bumptech/glide/wiki/Debugging-and-Error-Handling
Here's an example how that helps: https://github.com/bumptech/glide/issues/468
Feel free to ask more if this is not enough.
+Robi
To view this discussion on the web visit https://groups.google.com/d/msgid/glidelibrary/8cb4e825-6dfc-47bd-badb-fa95d215c888%40googlegroups.com.
Glide.with(activity)
.using(new StreamModelLoader<String>() {
@Override
public DataFetcher<InputStream> getResourceFetcher(final String model, int i, int i1) {
return new DataFetcher<InputStream>() {
@Override
public InputStream loadData(Priority priority) throws Exception {
throw new IOException();
}
@Override
public void cleanup() {
}
@Override
public String getId() {
return model;
}
@Override
public void cancel() {
}
};
}
})
.load(urlStr)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
...