缓存

iOS macOS

在易失性内存中,将值或对象保存一段预定时间。

用法

针对 UUID 实例暂存资源。

struct TestValue: Identifiable {
    let id: UUID
    let image: UIImage
}
let cache = Cache<TestValue>()
cache.stash(value, duration: .short)

// retrieve using the same `id` value.
let value: TestValue? = cache.resource(for: value.id)

安装

使用 Swift 包管理器。参见发布