Created
June 16, 2011 20:19
-
-
Save deltheil/1030162 to your computer and use it in GitHub Desktop.
Three20 TTImageView always checks the in-memory cache *without* using any expiration age - this version solves this problem
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
#import "MSImageView.h" | |
#import <Three20Network/TTURLCache.h> | |
#import <Three20Network/TTURLImageResponse.h> | |
#import <Three20Network/TTURLRequest.h> | |
#import "MSGlobals.h" | |
@implementation MSImageView | |
- (void)reload { | |
if (nil == _request && nil != _urlPath) { | |
UIImage* image = nil; | |
TTURLCache* cacheStore = [TTURLCache sharedCache]; | |
if ([cacheStore hasDataForKey:[cacheStore keyForURL:_urlPath] expires:MS_DEFAULT_IMAGE_CACHE_EXPIRATION_AGE]) { | |
image = [cacheStore imageForURL:_urlPath fromDisk:NO]; | |
if (!image) { | |
// The image can't be found in-memory so fetch the disk | |
image = [UIImage imageWithData:[cacheStore dataForURL:_urlPath]]; | |
} | |
} | |
else { | |
// Make sure to remove the stale image (if any) before requesting for the new one | |
[cacheStore removeURL:_urlPath fromDisk:YES]; | |
} | |
if (image == nil) { | |
// By default the cache policy is memory + disk + network | |
TTURLRequest* request = [TTURLRequest requestWithURL:_urlPath delegate:self]; | |
request.response = [[[TTURLImageResponse alloc] init] autorelease]; | |
if (![request send]) { | |
if (_defaultImage && self.image == nil) { | |
[super setImage:_defaultImage]; | |
} | |
} | |
} | |
else | |
[super setImage:image]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment