android cache 框架,Android 缓存框架之ManbaCacheManager

ManbaCacheManager

ManbaCacheManager是Android缓存管理器,分为两级缓存:内存缓存和外部存储介质缓存;先取内存数据,没有再从外部存储介质中读取数据。

特点

二级缓存

内存缓存:采用LruCache实现

外部存储介质缓存:采用DiskLruCache实现

默认使用SD卡缓存

支持的数据类型:String

默认内存缓存优先

采用单例模式创建缓存管理器,再结合简单工厂模式,创建存储模式。

写缓存流程图

open=>start: open

close=>end: End

init=>operation: init

Strategy=>condition: MEMORY_FIRST or MEMORY_ONLY ?

memoryOnly=>operation: memoryOnly

memoryFirst=>operation: memory with Disk

open->init->Strategy

Strategy(yes)->memoryFirst->close

Strategy(no)->memoryOnly->close

注:MEMORY_FIRST:内存缓存优先,外部存储缓存为辅;MEMORY_ONLY:只有内存缓存

读缓存流程图

open=>start: open

close=>end: End

init=>operation: init

Strategy=>condition: MEMORY_FIRST or MEMORY_ONLY ?

memoryOnly=>operation: memoryOnly

memoryFirst=>operation: memory with Disk

memoryCache=>condition: Yes or No ?

readMemoryCache=>operation: readMemoryCache

readDiskMemoryCache=>operation: readDiskMemoryCache

open->init->Strategy

Strategy(yes)->memoryFirst->memoryCache

Strategy(no)->memoryOnly->close

memoryCache(yes)->readMemoryCache->close

memoryCache(no)->readDiskMemoryCache->close

使用方法

ManbaCacheManager.getInstance(context, ManbaCacheManager.Strategy.MEMORY_FIRST);

//读数据

mCacheManager.readCache(CacheKey);

//写数据

mCacheManager.writeCache(CacheKey, data);

//移除数据

mCacheManager.removeMemoryCache(CacheKey);

每天多努力那么一点点,积少成多

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值