Skip to content

Instantly share code, notes, and snippets.

@exce11ent
Created November 13, 2013 14:18
Show Gist options
  • Save exce11ent/7449848 to your computer and use it in GitHub Desktop.
Save exce11ent/7449848 to your computer and use it in GitHub Desktop.
+(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