Skip to content

dkarchive/DKDataCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DKDataCache

Simple iOS Data Cache

Build Status Version License Platform

DKDataCache can be used to cache images retrieved from an URL

Installation

pod 'DKDataCache'

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.