抽空看了下github的开源项目:,感觉里边的内容还是比较多,需要总结。
本文的目的:
1,项目的整体结构
2,相关处理的分类
3,算法相关的总结
4,多线程的总结
一,代码的整体的结构。
代码结构图
代码的结构很清新,相关的分类很详细,应该会满足大多数人的需求。此处不涉及如何使用此开源项目,之探讨源码。
二,相关处理的分类(不一一列举,参看代码结构图,即是列举)
1,sdcard文件缓存限制分类
2,sdcard文件命名方法分类
3,内存缓存限制分类
4,BitmapDisplay的方式
三,算法相关总结
1,生成文件名 md5
1-1用途:
MD5: Message DigestAlgorithm 5 信息摘要算法
用于确保信息传输完整一致。让大容量信息在用数字签名软件签署私人密钥。前被“压缩”成一种保密的格式(就是把一个任意长度的字节串变换成一定长的十六进制的数字串)。任何人对文件做了任何改动,其MD5值都会发生变化。可称之为“数字指纹”。
1-2 原理:
MD5以512位分组来处理输入的信息,且每一分组又被划分为16个32位子分组,经过了一系列的处理后,算法的输出由四个32位分组组成,将这四个32位分组级联后将生成一个128位散列值。
w:基本的意思应该是数据分组,组合,然后经过一系列复杂的运算。
2,内存缓存方式
2-1FIFOLimitedMemoryCache
对此类的注释如下:
/** * Limited {@link Bitmap bitmap} cache. Provides {@link Bitmap bitmaps} storing. Size of all stored bitmaps will not to * exceed size limit. When cache reaches limit size then cache clearing is processed by FIFO principle. * * NOTE: This cache uses strong and weak references for stored Bitmaps. Strong references - for limited count of * Bitmaps (depends on cache size), weak references - for all other cached Bitmaps. * * @author Sergey Tarasevich (nostra13[at]gmail[dot]com) * @since 1.0.0 */
FIFO Priciple: First inFirst Out
优点:先进入的先完成并先退出,跟着才执行第二条指令
缺点:只能顺序写入数据,顺序的读出数据。
2-2LRULimitedMemoryCache
对此类的注释如下:
/** * Limited {@link Bitmap bitmap} cache. Provides {@link Bitmap bitmaps} storing. Size of all stored bitmaps will not to * exceed size limit. When cache reaches limit size then the least recently used bitmap is deleted from cache. * * NOTE: This cache uses strong and weak references for stored Bitmaps. Strong references - for limited count of * Bitmaps (depends on cache size), weak references - for all other cached Bitmaps. * * @author Sergey Tarasevich (nostra13[at]gmail[dot]com) * @since 1.3.0 */
LRU: least recently used
实质:当内存不够时,将清掉使用时间最老的缓存。
2-3 LruMemoryCache
对此类的注释如下:
/** * A cache that holds strong references to a limited number of Bitmaps. Each time a Bitmap is accessed, it is moved to * the head of a queue. When a Bitmap is added to a full cache, the Bitmap at the end of that queue is evicted and may * become eligible for garbage collection. * * NOTE: This cache uses only strong references for stored Bitmaps. * * @author Sergey Tarasevich (nostra13[at]gmail[dot]com) * @since 1.8.1 */
实质:当某一个bitmap被访问时,它被移到队首,当内存不够时,从队尾清
2-4UsingFreqLimitedMemoryCache
对此类的注释如下:
/** * Limited {@link Bitmap bitmap} cache. Provides {@link Bitmap bitmaps} storing. Size of all stored bitmaps will not to * exceed size limit. When cache reaches limit size then the bitmap which used the least frequently is deleted from * cache. * * NOTE: This cache uses strong and weak references for stored Bitmaps. Strong references - for limited count of * Bitmaps (depends on cache size), weak references - for all other cached Bitmaps. * * @author Sergey Tarasevich (nostra13[at]gmail[dot]com) * @since 1.0.0 */
实质,当内存不够时,将清掉使用频率最低的缓存。
2-5 WeakMemoryCache
弱引用,请参看之前的blog:
四,多线程:
参考文章:
未完:需要看完项目中自己实现的类。