JSON and String • First-level memory cache using NSCache • Second-level LRU disk cache using the file system • Asynchronous fetching from network or disk
JSON from (in order) memory, disk or NSURLCache. 2. If not available, fetch the JSON from the url, parse it and return it asynchronously. 3. And immediately afterwards cache the JSON in background.
an appropriately sized image from the memory or disk cache (in background). • If not cached, loading the original from its source and producing an appropriately sized image (both in background). • Remote images will also be retrieved from the shared NSURLCache if available.
appropriate. • Or doing nothing if the UIImageView was reused during any of the above steps. • Caching the resulting image. • If needed, evicting the least recently used images in the cache.
"icons") { image in return imageByRoundingCornersOfImage(image) } cache.addFormat(iconFormat) let URL = NSURL(string: "http://haneke.io/icon.png")! cache.fetch(URL: URL, formatName: "icons").onSuccess { image in // image will be a nice rounded icon }
convenience methods. Under the hood Haneke uses fetcher objects: let URL = NSURL(string: "http://haneke.io/icon.png")! let fetcher = NetworkFetcher<UIImage>(URL: URL) cache.fetch(fetcher: fetcher).onSuccess { image in // Do something with image }
• Providing the key associated with the value to be fetched (e.g., NSURL.absoluteString in the case of NetworkFetcher) • Fetching the value in background and calling the success or failure closure (both in the main queue) • Cancelling the fetch on demand, if possible Type restriction: must implement DataConvertible.