ios - 为什么 kingfisher 使用 md5 创建 cacheFileName?
问题描述
为什么 kingfisher 使用 md5 创建 cacheFileName?是否有其他特殊原因?
// DiskStorage.swift in Kingfisher
func cacheFileName(forKey key: String) -> String {
if config.usesHashedFileName {
let hashedKey = key.kf.md5
if let ext = config.pathExtension {
return "\(hashedKey).\(ext)"
} else if config.autoExtAfterHashedFileName,
let ext = key.kf.ext {
return "\(hashedKey).\(ext)"
}
return hashedKey
} else {
if let ext = config.pathExtension {
return "\(key).\(ext)"
}
return key
}
}
解决方案
使用文件的 md5 作为缓存中的文件名是一种常见模式。文件更改时缓存名称会更改,而源 url 可能不会。
请注意,保留扩展名是因为以后使用该文件时可能会很方便。
推荐阅读
- sql - 如果与外键约束一起使用,“非空”约束是否多余?
- jquery - jQuery UI Datepicker 您选择的日期是星期六或星期日
- python-3.x - 如何使用python绘制带有一些文本的reactangle
- r - ggplot:将标签添加到 geom_line aes_string
- python - 我正在尝试编写一个代码来打印 'a' 范围内不能被 y 整除的数字
- javascript - 为什么函数后面有两个括号
- angular - 如何用 MatGridList 实现动态列?
- python - 如何在python中将蛋白质序列分成20个相等的大小
- mongoose - Mongoose Schema:强制执行互斥键
- regex - 从单行捕获多组字符