TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Apr 2015 |
Maintained by Daniel Khamsing.
Simple iOS Data Cache
DKDataCache can be used to cache images retrieved from an URL
Add the files in the DKDataCache folder to your project.
NSString *key = @"http://lorempixel.com/100/100/cats/2/";
// get cache
NSData *data = [[DKDataCache sharedInstance] dataForKey:key];
if (data) {
UIImage *image = [UIImage imageWithData:data];
// yay
return;
}
NSURL *url = [NSURL URLWithString:key];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (data) {
// set cache
[[DKDataCache sharedInstance] cacheData:data forKey:key];
UIImage *image = [UIImage imageWithData:data];
// nice
}
}];
DKDataCache includes a sample project in the Demo
folder.
DKDataCache is available under the MIT license. See the LICENSE file for more info.