Android的通用图像装载机:加载图像时,旁通盘/内存缓存检查? [英] Android Universal Image Loader: by-pass disc/memory cache check when loading an image?
问题描述
该库只露出选项来启用在显示选项/禁用缓存。有没有一种方法,以避免光盘或存储缓存检查加载图像时?
The library only exposed option to enable/disable caching in display options. Is there a way to avoid disc or memory cache check when loading images?
我的问题是,库总是先检查光盘的高速缓存。我的盘缓存设置的小缩略图的大小。当我需要加载图像的屏幕尺寸,我不能跳过光盘高速缓存,它总是让我的较低分辨率图像。
My problem is that the library always check the disc cache first. My disc cache is set with small thumbnail size. When I need to load images for screen size, I cannot skip the disc cache , it always get me the lower resolution image.
推荐答案
UIL显示之前经常检查缓存。因此,有没有办法避免不changins来源。
UIL always check caches before displaying. So there is no way to avoid without changins the sources.
但我认为你可以通过扩展磁盘高速缓存解决您的问题。我们的目标是当你要加载的全尺寸图像返回从的get()
方法不存在的文件。
所以,你应该做和往常一样来加载缩略图。当你需要显示全尺寸的图像,你应该禁用磁盘上的显示选项( DisplayImageOptions
),然后缓存做这样的事情:
But I think you can solve your problem by extending disk cache. The goal is to return non-existing file from get()
method when you want to load full-sized image.
So you should do as usual to load thumbnails. When you need to display full-sized image you should disable caching on disk in display options (DisplayImageOptions
) and then do something like this:
((MyDiscCache) imageLoader.getDiscCache()).setIgnoreDiskCache(true);
所以,你的缓存必须返回任何不存在的文件(但不能为null)。
So your cache must return any non-existing file (but not null).
当您返回到显示的缩略图,你应该使能( setIgnoreDiskCache(假)
)的磁盘缓存回来了。
When you return to display thumbnails you should "enable" (setIgnoreDiskCache(false)
) disk cache back.
UPD: 创建自己的磁盘缓存,并将其设置为配置。
UPD: Create your own disk cache and set it to config.
public class MyDiscCache extends UnlimitedDiscCache {
private boolean ignoreDiskCache;
public MyDiscCache(File cacheDir) {
super(cacheDir);
}
public MyDiscCache(File cacheDir, FileNameGenerator fileNameGenerator) {
super(cacheDir, fileNameGenerator);
}
@Override
public File get(String key) {
if (ignoreDiskCache) {
return new File("fakePath");
} else {
return super.get(key);
}
}
public void setIgnoreDiskCache(boolean ignoreDiskCache) {
this.ignoreDiskCache = ignoreDiskCache;
}
}
这篇关于Android的通用图像装载机:加载图像时,旁通盘/内存缓存检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!