Glide图片框架使用详细介绍(二)之缓存策略,flutter图片压缩库

本文详细介绍了Glide图片加载框架的内存和磁盘缓存策略,包括最大内存缓存计算、磁盘缓存大小设定以及如何清除缓存。提供了一个Glide缓存工具类,用于获取缓存大小和清理磁盘缓存。
摘要由CSDN通过智能技术生成

最大空间:

Glide的内存缓存其实涉及到比较多的计算,这里就介绍最重要的一个参数,就是内存缓存最大空间

内存缓存最大空间(maxSize)=每个进程可用的最大内存 * 0.4

(低配手机的话是: 每个进程可用的最大内存 * 0.33)

磁盘缓存大小

磁盘缓存大小: 250 * 1024 * 1024(250MB)

/** 250 MB of cache. */

int DEFAULT_DISK_CACHE_SIZE = 250 * 1024 * 1024;

磁盘缓存目录

磁盘缓存目录: 项目/cache/image_manager_disk_cache

String DEFAULT_DISK_CACHE_DIR = “image_manager_disk_cache”;

5、清除缓存

由于Glide可能会缓存一张图片的多个分辨率的图片,并且文件名是被哈希过的,所以并不能很好的删除单个资源的缓存,以下是官方文档中的描述

Because File names are hashed keys, there is no good way to simply delete all of the cached files on disk that correspond to a particular url or file path. The problem would be simpler if you were only ever allowed to load

or cache the original image, but since Glide also caches thumbnails and provides various transformations, each of which will result in a new File in the cache, tracking down an

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值