Save NSCache Contents to Disk

前端 未结 4 1908
不知归路
不知归路 2020-12-10 02:59

I\'m writing an app that needs to keep an in-memory cache of a bunch of objects, but that doesn\'t get out of hand so I\'m planning on using NSCache to store it all. Looks l

4条回答
  •  有刺的猬
    2020-12-10 03:28

    You should try AwesomeCache. Its main features:

    • written in Swift
    • uses on on-disk caching
    • backed by NSCache for maximum performance and support for expiry of single objects

    Example:

    do {
        let cache = try Cache(name: "awesomeCache")
    
        cache["name"] = "Alex"
        let name = cache["name"]
        cache["name"] = nil
    } catch _ {
        print("Something went wrong :(")
    }
    

提交回复
热议问题