iOS 通用緩存:HanekeSwift

jopen 10年前發布 | 87K 次閱讀 Apple Swift開發 HanekeSwift

Haneke 是個采用 Swift 編寫的輕量級 iOS 通用緩存。示例:

初始化一個數據緩存:

let cache = Cache<NSData>("my-files")

Haneke 同時包括一個零配置的圖片緩存,可以自動縮放。 示例:

imageView.hnk_setImageFromURL(url)

它的設計是超簡單易用。這里是你如何初始化一個JSON緩存和從URL獲取JSON對象:

let cache = Cache<JSON>("movies")
let URL = NSURL(string: "http://haneke.io/movies.json")
cache.fetch(URL: URL).onSuccess { JSON in
    // Do something with JSON
}

特性

  • Generic cache with out-of-the-box support for UIImage, NSData, JSON and String
  • First-level memory cache using NSCache
  • Second-level LRU disk cache using the file system
  • Asynchronous fetching of original values from network or disk
  • All disk access is performed in background
  • Thread-safe
  • Automatic cache eviction on memory warnings or disk capacity reached
  • Comprehensive unit tests
  • Extensible by defining custom formats, supporting additional types or implementing custom fetchers
  • </ul>

    項目主頁:http://www.baiduhome.net/lib/view/home/1412904232717

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!