问题标签 [android-lru-cache]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
android - 自定义网格视图中的 LRUCACHE
嗨,我在我的程序中使用包含 imageview 和 2 个 textFields 的自定义 gridView,在 getview 方法中,我正在使用从 Internet 获取的图像,使用 url 在 imageview 中显示图像。我需要使用 lrucache 来显示图像而不将下载的图像存储在外部存储中。有人帮我编写代码。
先感谢您
这是我的自定义 gridview 类
}
java - 将 LRU 图像缓存与 HTTPResponseCache 结合用于磁盘和内存缓存
最初的目标是同时使用磁盘和内存缓存。这需要实现 LRU 缓存和 DiskLruCache。但是,由于 HTTPResponse 缓存使用磁盘空间,我选择使用 LRU 缓存并执行 con.setUseCaches(true);
问题是我真的不明白首先实现的是什么。对于 LRU 和 DiskLru 缓存,算法如下:
IE
首先检查内存缓存中的图像
如果有图像,则返回并更新缓存
否则检查磁盘缓存
如果磁盘缓存有图像,则返回并更新缓存
否则从互联网下载图像,返回并更新缓存
现在使用下面的代码:
看起来好像在 doInBackground() 中我正在保存到 HttpResponseCache,而在 onPostExecute() 中我正在将相同的图像保存到 LRUCache。我想做的是:
如果图片没有缓存,则保存到 HttpResponseCache 如果 HttpResponseCache 已满,则保存到 LRUCache。如果两者都已满,请使用默认删除机制来删除旧的未使用图像。问题是保存到两个缓存而不是任何一个
编辑改写问题
**
由于两者都缓存相同的图像,两次并将缓存保存到同一个文件系统,也许问题应该是使用哪一个,因为使用两者似乎没有意义......
**
android - LruCache 内存不足?
在最后一行我遇到了崩溃:
如何避免?
我明白 31MB 是使用内存的限制吗?用于LRUCache
存储图像。我设置了 60MB 来存储数据。是不是太多了?
在我的例子中,一个图像大约是 3MB,我需要至少 18 个图像存储在缓存中。手机存储60MB的需求这么大吗?
我尝试了代码,为什么应用程序终止?
android - 通过意图传递大型文本数据。如何缓存它?
我通过 Intent 将一些数据传递给 DatabaseService。然而,当这个数据真的很庞大时,有一个用户的极端情况。我得到
E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
真可惜。
通常人们认为我尝试将位图传递给(虽然?)LruCache。好的,我可以使用 if 对象的数组列表吗?正如我所说 - 实际上这是来自服务器的响应,它是一个 JSON。
任何想法如何解决这个问题?有没有我不知道的特殊课程?
java - LRUCache entry reordering when using get
I checked out official Android documentation for LRUCache which says : Each time a value is accessed, it is moved to the head of a queue. When a value is added to a full cache, the value at the end of that queue is evicted and may become eligible for garbage collection. I suppose this is the doubly linked list which is maintained by linkedhashmap which is used by the cache. To check this behavior, I checked out the source code for LruCache, and checked the get(K key) method. It further calls upon map's get method which gets the value from the underlying hashmap and calls upon recordAccess method.
recordAccess method in turn moves the accessed entry to the end of the list in case accessOrder is set to true (for my problem let's assume it is), else it does nothing.
This sounds contradictory to the above statement where it's said that the element is moved to the head of the queue. Instead it's moved to the last element of the list (using head.before). Surely, I'm missing something here, any help?
android - Android 中用于位图(和其他)的 DiskLRUCache
在 android 中,许多图像加载库(如Picasso——它使用 2% 的存储空间用于磁盘缓存,Glide)除了内存中的 lru 缓存外,还使用磁盘缓存。我可以理解为什么这可能对从网络下载的图像有用——如果内存缓存已满,请从磁盘读取它而不是远程获取它们——从而避免网络延迟等。但是,如果我们只是读取本地图像在android设备本身上——我们是否通过使用带有序列化位图数据的单独磁盘缓存获得任何东西——因为无论如何都必须从磁盘读取数据?如果您的应用需要缩略图并对原始图像进行二次采样并将其存储在缓存中,这可能是有意义的吗?是否有任何研究显示性能增益。我在google 示例中看到了磁盘缓存的使用和其他位图缓存库。
android - 使用 Espresso 运行 Instrumentation 测试时删除 LruCache
我正在运行浓缩咖啡测试,并希望在每次测试运行时删除 LruCache。
我可以根据喜好这样做:
请让我知道如何为 LruCache 做同样的事情?
android - ViewPager 和 ListView 缓存
我有一个带有 4 个 ListViews 的 ViewPager。列表视图都下载唯一的图像,我想缓存它们,但出现错误,应用程序运行速度非常慢。有没有办法将所有图像缓存在 1 LruCache 或类似的东西中?这是我的代码到目前为止第一个列表适配器
}
另一个完全像这样,这是错误
android - LRUCache BitmapDrawable
我正在使用 LruCache 来缓存我的应用程序中使用的许多小型 BitmapDrawables。问题是我使用图像的不同地方的尺寸不同。
当我从缓存中检索可绘制对象时,我设置了边界,然后将其设置为 ImageView 以具有正确的大小。
当我设置边界时,drawable 也会在其他地方调整大小。
我怎样才能在不使用的情况下解决这个问题drawable.getConstantState().newDrawable()
?滚动列表视图时,从缓存的可绘制对象创建新的可绘制对象非常慢。
在 DynamicDrawableSpans 中使用了相同的图像,我无法在 span 本身上设置边界,只能直接在 drawable 上设置。
在单独的缓存中为不同的上下文缓存相同的可绘制图像是否明智?
android - Android - 带有 ImageView、LRUcache 和 ViewHolder 的滞后 ListView
我有一个ListView
,其中每一行都有一些文本和两个ImageView
:一个对于每一行都是相同的,另一个取决于当前项目。
这是我的适配器:
第一个ImageView
是Bitmap
存储在Exhibition
变量中。第二个更改文本的可见性以获得类似可扩展的效果(因为现在我无法将 转换ListView
为 a ExpandableListView
)。我尝试了不同的东西,比如缓存,一个AsyncTask
,删除自定义点击监听器,把所有东西都放进去,ViewHolder
但滚动充满了微滞后。适配器有什么问题我不明白吗?