Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to select EGOv1 style PNG only caching #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion EGOCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,34 @@ - (void)setString:(NSString*)aString forKey:(NSString*)key withTimeoutInterval:(

#if TARGET_OS_IPHONE

#if EGO_USE_PNG_ARCHIVING_IOS

- (UIImage*)imageForKey:(NSString*)key {

UIImage *image = [[UIImage alloc] initWithContentsOfFile:cachePathForKey(_directory,key)];

return image;
}

- (void)setImage:(UIImage*)anImage forKey:(NSString*)key {

[self setImage:anImage forKey:key withTimeoutInterval:self.defaultTimeoutInterval];
}

- (void)setImage:(UIImage*)anImage forKey:(NSString*)key withTimeoutInterval:(NSTimeInterval)timeoutInterval {

[self setData:UIImagePNGRepresentation(anImage) forKey:key withTimeoutInterval:timeoutInterval];
}

#else

- (UIImage*)imageForKey:(NSString*)key {
UIImage* image = nil;

@try {
image = [NSKeyedUnarchiver unarchiveObjectWithFile:cachePathForKey(_directory, key)];
} @catch (NSException* e) {
// Surpress any unarchiving exceptions and continue with nil
NSLog(@"**[EGOCache imageForKey:] - Unarchive has failed for some reason. ARC has leaked. If you are seeing a lot of these messages (especially where you dont control endpoint) you may wish to \"#define EGO_USE_PNG_ARCHIVING_IOS 1\"");
}

return image;
Expand All @@ -300,6 +321,9 @@ - (void)setImage:(UIImage*)anImage forKey:(NSString*)key withTimeoutInterval:(NS
}



#endif

#else

- (NSImage*)imageForKey:(NSString*)key {
Expand All @@ -315,6 +339,8 @@ - (void)setImage:(NSImage*)anImage forKey:(NSString*)key withTimeoutInterval:(NS
forKey:key withTimeoutInterval:timeoutInterval];
}



#endif

#pragma mark -
Expand Down