Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


AFCacheableItemInfo returning MIME type of 'plain/text' after first use #3

tonyarnold opened this Issue · 1 comment

2 participants


I've got an odd problem where I'm getting a MIME type of 'plain/text' on items that were previously 'image/jpeg' or 'video/mp4'. It seems to happen only after I've quit and restarted my app, or after I've recalled the item from cache already. Here's how I'm retrieving items from cache:

````AFCacheableItem *cacheableItem = [[AFCache sharedInstance] cachedObjectForURL:thumbnailFullSizeSrc delegate:nil];

Am I doing something wrong?

I have a similar problem.
I've made a modification in AFURLCache that seems to fix the problem : I have to split the content-type and the charset :

NSURL* url = request.URL;
AFCacheableItem* item = [[AFCache sharedInstance] cacheableItemFromCacheStore:url];
if (item && item.cacheStatus == kCacheStatusFresh && {
NSRange oRange = [ rangeOfString:@"charset="];
NSString* oMimeType =;
NSString* oCharset = nil;
if (oRange.location != NSNotFound)
oMimeType = [[[ substringToIndex:oRange.location] stringByReplacingOccurrencesOfString:@";" withString:@""]
stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
oCharset = [[ substringFromIndex:(oRange.location + oRange.length)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURLResponse* response = [[NSURLResponse alloc] initWithURL:item.url
expectedContentLength:[ length] textEncodingName:oCharset];
NSCachedURLResponse *cachedResponse = [[NSCachedURLResponse alloc] initWithResponse:response userInfo:nil storagePolicy:NSURLCacheStorageAllowedInMemoryOnly];
[response release];
NSLog(@"Cache HIT for file: %@", [[AFCache sharedInstance] filenameForURL: url]);
return [cachedResponse autorelease];
} else {
NSLog(@"Cache miss for file: %@", [[AFCache sharedInstance] filenameForURL: url]);

NSCachedURLResponse *response = [super cachedResponseForRequest:request];
return response;


Also I added a test on because sometimes I got nil which ends with a blank page in UIWebView.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.