用Swift编写的简单LRU缓存实现。此库受Cache::LRU的启发。
let cache = Siegel<Int?>(size: 3)
// set
cache.set(key: "a", value: 1)
cache.set(key: "b", value: 2)
cache.set(key: "c", value: nil)
cache.set(key: "d", value: 4)
cache["s"] = 10
// get
cache.get(key: "a") // => nil
cache.get(key: "b") // => 2
cache.get(key: "c") // => nil
cache.get(key: "4") // => 4
cache["s"] // => 10
// exists
cache.exists(key: "a") // => false
cache.exists(key: "b") // => true
cache.exists(key: "c") // => true (if using optional type, it can contain nil)
cache.exists(key: "d") // => true
cache.exists(key: "e") // => false
cache.exists(key: "s") // => true
// remove
cache.remove(key: "b")
cache.get(key: "b") // => nil
cache.exists(key: "b") // => false
// clear
cache.clear
cache.exists(key: "a") // => false
cache.exists(key: "b") // => false
cache.exists(key: "c") // => false
cache.exists(key: "d") // => false
cache.exists(key: "e") // => false
cache.exists(key: "s") // => false
Seigel可通过CocoaPods获取。要安装,只需将以下行添加到您的Podfile中
pod 'Siegel'
Mihyaeru, [email protected]
Seigel采用MIT许可证。更多信息请参见LICENSE文件。