android缓存机制
来源:互联网 发布:腾讯java工程师待遇 编辑:程序博客网 时间:2024/06/05 02:03
一般android会采用缓存机制,内存缓存采用LruCache,存储缓存采用DiskLruCache
LruCache内部维护了一个LinkedHashMap
/** * @param maxSize for caches that do not override {@link #sizeOf}, this is * the maximum number of entries in the cache. For all other caches, * this is the maximum sum of the sizes of the entries in this cache. */ public LruCache(int maxSize) { if (maxSize <= 0) { throw new IllegalArgumentException("maxSize <= 0"); } this.maxSize = maxSize; this.map = new LinkedHashMap<K, V>(0, 0.75f, true); }
同时是线程安全的
synchronized (this) { mapValue = map.get(key); if (mapValue != null) { hitCount++; return mapValue; } missCount++; } synchronized (this) { createCount++; mapValue = map.put(key, createdValue); if (mapValue != null) { // There was a conflict so undo that last put map.put(key, mapValue); } else { size += safeSizeOf(key, createdValue); } }
一般存储空间为当前运行空间的1/8 单位为KB
LruCache 3.1以后源码可见
DiskLruCache 一般存储空间为50M key采用url经过Md5加密,防止url中的特殊字符,value为bitmap,对外提供get,put方法
0 0
- android缓存机制
- Android webView缓存机制
- Android 缓存机制续
- Android 缓存机制
- Android 图片缓存机制
- Android WebView缓存机制
- Android:缓存机制
- Android WebView缓存机制
- Android 缓存机制
- Android 缓存机制
- Android 缓存机制
- Android 缓存机制
- Android缓存机制
- android缓存机制
- Android三级缓存机制
- Android缓存机制
- Android缓存机制学习
- android缓存的机制
- CSS—display取值
- 图文介绍openLDAP在windows上的安装配置
- 记录小菜鸟的我的每一次成长
- k580s笔记本音量不停自增或自减
- php中的exception与自定义异常类
- android缓存机制
- JDK 8 函数式编程入门
- u-boot 2013.01.01 Makefile分析
- 测试某硬件平台下python能启动的最大线程数
- 嵌入式系统调试手段及方法综述
- JVM性能调优
- jmeter中put方法参数使用
- Python pandas 数据框的str列内置的方法详解
- Leetcode-89 Gray Code