SwimplyCache
这是什么?
SwimplyCache 是一个简单、线程安全的缓存解决方案。它内部由 LinkedHashMap 支持且相对于 NSCache 而言非常快速。
SwimplyCache 在遇到内存警告或应用后台事件时,会自动清空。
使用
创建缓存
let cache = SwimplyCache<String, String>()
增加值
cache.setValue("Value", forKey: "Key")
cache.setValue("Value", forKey: "Key", costs: 200)
检索值
let value = cache.value(forKey: "Key")
移除值
Swimply 允许您通过以下操作来移除值。
cache.remove(.key(key: "Key"))
cache.remove(.all)
cache.remove(.byLimit(countLimit: 200))
cache.remove(.byCost(costLimit: 200))