安卓缓存>内部存储与对象缓存
我需要缓存来自网络的图像(仅 5 个或最多 100 个)并显示在列表视图中。如果用户选择列表视图的一行,则可以清除缓存。我看了一些例子。有些使用外部存储。有些使用内部和外部。一些对象..
那么内部存储的优点/缺点是什么( http://developer.android.com/guide/topics/data/data-storage.html#filesInternal 通过 getCacheDir())和对象缓存(类似于 WeakHashMap 或HashMap < 字符串、软引用 < 可绘制 > )
软引用的一个问题似乎是它们可能会被垃圾收集得太快( 软引用也会被垃圾收集早)。安卓内部存储怎么样?参考文献说“当设备存储空间不足时,这些文件将首先被删除。”。
使用对象缓存或临时内部存储有什么区别吗?除了对象缓存应该更快一点
i need to cache images (only 5 or up to 100) from the web and displayed in a listview. if the user selects a row of the listview the cache can be cleared. i had a look on some examples. some use external storage. some use internal and external. some objects..
so what are the advantages/disadvantages of internal storage ( http://developer.android.com/guide/topics/data/data-storage.html#filesInternal via getCacheDir()) and object cache (something like WeakHashMap or HashMap < String, SoftReference < Drawable > )?
a problem with softreferences seems to be that they may get gc'ed too fast ( SoftReference gets garbage collected too early) . what about the android internal storage? the reference sais "These files will be ones that get deleted first when the device runs low on storage.".
does it make any difference to use a object cache or the temporary internal storage? except for the object cache should be a bit faster
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是两者之间的一些区别:
现在考虑到这些差异,它们并不完全相互排斥。我们实现的很多功能都是使用多层缓存,特别是与图像加载相关的缓存。以下是我们使用的步骤:
我们已经将多层缓存作为一个通用组件,并在我们的客户的许多项目中使用了它。这种技术非常类似于计算机体系结构中的 L1、L2 缓存。
Here are the few differences between the two:
Now given those differences, they are not totally mutually exclusive. A lot of we implemented is using multi layer caching especially related to the image loading. Here are the steps that we use:
We have made the multi layers caching a common component and have used it many of our projects for our clients. This technique is pretty much following to what L1, L2 cache in Computer Architecture.
您应该寻找问题“如何我是否会懒惰地下载 ListView 中的图像” 及相关内容。
You should look for the question "How do I lazy download images in ListView" and related.