Don't cache my NSURLResponse
Don't cache my NSURLResponse
- Subject: Don't cache my NSURLResponse
- From: Glen Simmons <email@hidden>
- Date: Thu, 24 Nov 2005 09:37:38 -0600
I'm converting XHTML to an NSAttributedString using -
initWithData:options:documentAttributes:error:. There are img tags in
the XHTML that look like this:
<img src="foo://0.png"/>
The image data is in my data model, so I'm using a subclass of
NSURLProtocol to supply it. This is working fine until I load a
different bit of XHTML that also happens to have an img tag with the
same URL. It's actually a different image, but the framework is
apparently caching the data for that URL b/c I don't get called and
the first image shows up. My NSURLProtocol subclass' -startLoading
method looks like this:
id<NSURLProtocolClient> client = [self client];
NSURLRequest* request = [self request];
NSString* mimeType = @"image/png";
NSData* data;
data = [dataProvider generateDataForRequest:request];
if (data && mimeType) {
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:
[request URL]
MIMEType:mimeType
expectedContentLength:-1
textEncodingName:nil];
[client URLProtocol:self
didReceiveResponse:response
cacheStoragePolicy:NSURLCacheStorageNotAllowed];
[client URLProtocol:self didLoadData:data];
[client URLProtocolDidFinishLoading:self];
[response release];
} else {
int resultCode;
resultCode = NSURLErrorResourceUnavailable;
[client URLProtocol:self didFailWithError:[NSError
errorWithDomain:NSURLErrorDomain code:resultCode userInfo:nil]];
}
Notice that I'm passing NSURLCacheStorageNotAllowed to -
URLProtocol:didReceiveResponse:cacheStoragePolicy:, but it's still
caching. Suggestions?
Thanks,
Glen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden