Created
November 13, 2013 14:18
-
-
Save exce11ent/7449848 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(NSString *)cacheFilenameForURL:(NSURL *)resourceURL atSize:(CGSize)size atScaleFactor:(CGFloat)scaleFactor atPage:(int)page | |
{ | |
NSString *cacheFilename = nil; | |
#ifdef UIIMAGE_PDF_CACHEING | |
NSFileManager *fileManager = [ NSFileManager defaultManager ]; | |
NSString *filePath = [ resourceURL path ]; | |
//NSLog( @"filePath: %@", filePath ); | |
NSDictionary *fileAttributes = [ fileManager attributesOfItemAtPath:filePath error:NULL ]; | |
//NSLog( @"fileAttributes: %@", fileAttributes ); | |
NSString *cacheRoot = [ NSString stringWithFormat:@"%@ - %@ - %@ - %@ - %d", [ filePath lastPathComponent ], [ fileAttributes objectForKey:NSFileSize ], [ fileAttributes objectForKey:NSFileModificationDate ], NSStringFromCGSize(CGSizeMake( size.width * scaleFactor, size.height * scaleFactor )), page ]; | |
//NSLog( @"cacheRoot: %@", cacheRoot ); | |
NSString *MD5 = [ cacheRoot MD5 ]; | |
//NSLog( @"MD5: %@", MD5 ); | |
NSString *cachesDirectory = [ NSSearchPathForDirectoriesInDomains( NSCachesDirectory, NSUserDomainMask, YES ) objectAtIndex:0 ]; | |
NSString *cacheDirectory = [ NSString stringWithFormat:@"%@/__PDF_CACHE__", cachesDirectory ]; | |
//NSLog( @"cacheDirectory: %@", cacheDirectory ); | |
[ fileManager createDirectoryAtPath:cacheDirectory withIntermediateDirectories:YES attributes:nil error:NULL ]; | |
cacheFilename = [ NSString stringWithFormat:@"%@/%@.png", cacheDirectory, MD5 ]; | |
//NSLog( @"cacheFilename: %@", cacheFilename ); | |
#endif | |
return cacheFilename; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment