android - 如何强制将图像添加到磁盘缓存

标签 android caching universal-image-loader

我在手动将本地镜像添加到磁盘缓存时遇到问题。原因是我有一张本地照片,需要上传这张。但是因为我知道 URL 结果,所以我想立即缓存它。我正在使用

ImageLoader.getInstance().getDiscCache().put(imageUrl, new File(tempFileURI));

但这不起作用,因为当我使用下面的行时,文件返回 null

File thumb=
DiscCacheUtil.findInCache(urlThumbSize,ImageLoader.getInstance().getDiscCache());

有什么想法吗?

最佳答案

实际上,DiscCache 并不打算直接使用。 DiscCache.put() 不会将您的文件复制到磁盘缓存中。如果它是有限的缓存,它只是控制缓存大小。 您应该自己将图像文件复制到缓存目录中:

File fileInDiscCache = discCache.get(imageUri);
// copy your file into 'fileInDiscCache' file
discCache.put(imageUri, fileInDiscCache);

关于android - 如何强制将图像添加到磁盘缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20684949/

相关文章:

android - 清除安卓缓存

java - 如何异步处理 GAE 数据存储争用?

c# - 缓存具有类似性能的内存数据集并将其与数据库更改相关联的最佳方法是什么?

android - 如何扩展 Android Universal Image Loader 以下载 2 个或更多文件?

androidx.navigation 库更新到 2.2.2 版本发布构建问题

android - 将 post 数组改造为 php 文件

javascript - 如何更改 TextInput 上的光标位置? ( native react )

java - 如何在 Intent 中传递 Parcelable?

android - 通话相互重叠

android - 升级到新版本 1.9.5 后,Universal Image Loader 无法正常工作