- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 jake wharton DiskLruCache 库实现基于磁盘的图像 lru 缓存。 link to library .我正在使用 here 中的代码 fragment .
我遇到问题的方法是这个
private boolean writeBitmapToFile(Bitmap bitmap, DiskLruCache.Editor editor)
throws IOException, FileNotFoundException {
OutputStream out = null;
try {
out = new BufferedOutputStream(editor.newOutputStream(0), Utils.IO_BUFFER_SIZE);
return bitmap.compress(mCompressFormat, mCompressQuality, out);
} finally {
if (out != null) {
out.close();
}
}
}
其中 editor.newOutputStream(0) 不存在,而这个
public Bitmap getBitmap(String key) {
Bitmap bitmap = null;
DiskLruCache.Snapshot snapshot = null;
try {
snapshot = mDiskCache.get(key);
if (snapshot == null) {
return null;
}
final InputStream in = snapshot.getInputStream(0);
if (in != null) {
final BufferedInputStream buffIn =
new BufferedInputStream(in, Utils.IO_BUFFER_SIZE);
bitmap = BitmapFactory.decodeStream(buffIn);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (snapshot != null) {
snapshot.close();
}
}
Log.d("cache_test_DISK_", bitmap == null ? "" : "image read from disk " + key);
return bitmap;
}
其中 snapshot.getInputStream(0) 也不存在。
我做错了什么?我已将 jar 与库放在一起,一切正常,这些方法是否已从 DiskLruCache 库中删除?现在还有其他方法吗?我找不到任何示例或教程。
库版本为最新的disklrucache-2.0.2
最佳答案
确保您导入了正确的类:
导入 com.jakewharton.disklrucache.DiskLruCache
关于android - 使用 DiskLruCache 实现图片 Lru 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28967252/
题目地址:https://leetcode.com/problems/lru-cache/ 题目描述 Design and implement a data structure for Least
我使用 redis 作为数据存储而不是缓存,但是设置了 maxmemory 限制,据我了解,maxmemory 指定了 redis 可以使用的 RAM,如果达到内存限制,它不应该将数据交换回磁盘。 我
假设redis 实例中的所有键都设置了过期时间,volatile-lru 和allkeys-lru 是相似的。但是,当删除 key 时,两者之间是否存在显着的性能差异? 奖励问题: 在配置了 allk
LRU-K 是一种缓存淘汰算法,旨在改进传统的LRU(Least Recently Used,最近最少使用)算法的性能。将其中高频的数据达到K次访问移入到另一个队列进行保护。 算法思想 LR
1.题目 请你设计并实现一个满足 LRU (最近最少使用) 缓存 约束的数据结构。 实现 LRUCache 类: ① LRUCache(int capacity) 以正整数作为容量 capacity
如果 memcached 中的某个项目设置为永不过期,它是否免于 LRU 驱逐? 我见过的文档并没有清楚地描绘出哪个优先。在我看来,让 LRU 仅适用于过期 > 0 的项目是理想的(可能在内部非常复杂
当 memcache 中可用内存已满时,memcache 使用 LRU(最近使用的)算法来释放内存。 我的问题是 LRU 算法是否会删除在一段时间内(最近一次使用)未使用的条目而不是过期的条目? 即将
我在java中使用LRU缓存并覆盖了removeEldest。 @Override protected boolean removeEldestEntry (Map.Entry eldest) {
我前段时间已经发帖询问LRU缓存的良好设计(C++)。您可以在此处找到问题、答案和一些代码: Better understanding the LRU algorithm 我现在尝试对这段代码进行多线
我正在尝试使用这个 youtube video 自学 LRU 算法.在下面的示例 ( taken from here ) 中,为什么 0 被 3 代替。不应该是 4 被 3 代替,因为 4 是最少使用
我正在尝试使用 Caffeine 作为 LRU 缓存,因此首先添加的条目将首先被逐出。运行这段代码: final Cache map = Caffeine.newBuilder()
我对算法LRU有一点疑问。如果您有一个包含四个 block 的缓存,您需要多少位来实现该算法? 最佳答案 假设您指的是 4 路组相联缓存: “完美”的 LRU 本质上是按照使用顺序为每一行分配一个准确
我有两种类型的 Redis 键:post:{pid} 和 comment:{cid}。 我想存储最多 100 条记录的任一类型的缓存。 例如我有 100 条帖子记录和 50 条评论记录。当评论记录到来
我正在使用 Swift 构建一个应用程序,我想在我的应用程序中使用 LRU 缓存。我实现了一个简单的 LRUCache在 Swift 中,但后来我发现,由于它已经附带了 Dictionary 和 Ar
现在软件或者网页的并发量越来越大了,大量请求直接操作数据库会对数据库造成很大的压力,处理大量连接和请求就会需要很长时间,但是实际中百分之80的数据是很少更改的,这样就可以引入缓存来进行读取,减少数据
我有一些看起来像这样的代码: from functools import lru_cache @lru_cache() def get_cheese(type): print('{}? We\
我有一个规范,我试图定义一个 LRU 缓存系统,我遇到的一个问题是如何从结构键/值对(基本上是字典或哈希映射)中删除值其他语言)。 到目前为止,这是规范本身(不完整): EXTENDS Integer
如何使用 Erlang 实现 LRU 缓存? LRU Cache Wiki 最受关注的 Github 项目是 fogfish/cache ,但分段表不太适合我的数据。 barrel-db/erlang
我正在制作一个 Android 应用程序,其中有带有缩略图的新闻文章。这些缩略图从网络加载并存储在 LruCache 中,其中 URL 作为键,位图作为值。 private LruCache tCac
这个问题已经有答案了: How would you implement an LRU cache in Java? (21 个回答) 已关闭 5 年前。 我想仅使用 Java 内置的数据结构在 Jav
我是一名优秀的程序员,十分优秀!