// ViewController.m#import "ViewController.h"#import <CommonCrypto/CommonDigest.h> // use MD5 Hash URL @implementation ViewController- (void)viewDidLoad{ [super viewDidLoad]; NSURL *url = [NSURL URLWithString:@"http://cdn.duitang.com/uploads/item/201303/16/20130316195915_SEM4P.thumb.600_0.jpeg"]; NSLog(@"%@", [self cachePathForKey:[url absoluteString]]); NSLog(@"%@", [self cachePathForKey:@"http://b.hiphotos.bdimg.com/album/s%3D900%3Bq%3D90/sign=d43e9d6042166d223c771994761878ca/b03533fa828ba61e2916d2844034970a314e59a4.jpg"]);}- (NSString *)cachePathForKey:(NSString *)key{ const char *str = [key UTF8String]; unsigned char r[CC_MD5_DIGEST_LENGTH]; CC_MD5(str, (CC_LONG)strlen(str), r); NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15]]; return [diskCachePath stringByAppendingPathComponent:filename];}@end