测试已测试 | ✓ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最新发布 | 2016年10月 |
SwiftSwift版本 | 3.0 |
SPM支持SPM | ✗ |
由 Iurii Nechaev 维护。
YNImageAsync 是一个轻量级且方便的用于获取和缓存图像的框架。
if let url = URL(string: "https://upload.wikimedia.org/wikipedia/en/5/5f/Original_Doge_meme.jpg") {
imageView.setImageWithUrl(url)
}
imageView.cancelPreviousLoading()
// Initialize cache with 30 Mb memory capacity and disk caching
let cacheProvider = CacheProvider(configuration: CacheConfiguration(options: [.memory, .disk], memoryCacheLimit: 30 * 1024 * 1024))
// Save cache to memory and disk
cacheProvider.cacheData("key", data)
// Get cached data for key
provider.cacheForKey(image, completion: { (data) in
if let cacheData = data {
print("Cache hit")
} else {
print("Cache miss")
}
})
要更改最大内存缓存容量,您不需要初始化新的缓存提供程序实例。
// New memory capacity is 10 Mb
let newLimit: Int64 = 10 * 1024 * 1024
provider.configuration.memoryCacheLimit = newLimit
// Perform memory clean operation if capacity was reduced
provider.cleanMemoryCache()
您可以在初始化期间以及运行时轻松配置存储。
provider.configuration.options = .memory