简体   繁体   English

Android Universal Image Loader按ID缓存

[英]Android Universal Image Loader cache by id

I'm using NOSTRA's Universal Image Loader library and I have caching in memory enabled. 我正在使用NOSTRA的Universal Image Loader库,并且启用了内存缓存。 It seems that the bitmaps are cached using the URI set in the displayImage() method as the key. 似乎是使用displayImage()方法中设置的URI作为键来缓存位图的。 As a workaround I created another HashMap that contains the URIs for the images, with a unique id associated with it as the key. 作为解决方法,我创建了另一个HashMap,其中包含图像的URI,并具有与之关联的唯一ID作为键。 The reason for that is the id value is also used to load data in other places, so that value is unique for each image. 原因是id值也用于在其他地方加载数据,因此该值对于每个图像都是唯一的。

So is there a way to change the key for the cached bitmap to something other than the URI? 那么有没有办法将缓存位图的密钥更改为URI以外的其他内容?

Bitmap are cached in memory cache by key pattern [imageUrl]_[width]x[height] . 位图通过键模式[imageUrl] _ [width] x [height]缓存在内存缓存中。 There is no way to change this pattern in current lib version (1.7.0). 在当前的lib版本(1.7.0)中无法更改此模式。

@ NOSTRA : Can we do like this. @ NOSTRA:我们可以这样吗? instead of passing [imageUrl]_[width]x[height] while generating cachekey we can just pass our unique ID for cache key. 不用在生成cachekey时传递[imageUrl] _ [width] x [height],我们只需传递我们唯一的ID即可作为cache键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM