DKDataCache 0.2

DKDataCache 0.2

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

Installation

Manual

Add the files in the DKDataCache folder to your project.

Usage

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
  }
}];

Demo

DKDataCache includes a sample project in the Demo folder.

Contact

License

DKDataCache is available under the MIT license. See the LICENSE file for more info.