WebKit/URL Loading System/NSURLCache problem
WebKit/URL Loading System/NSURLCache problem
- Subject: WebKit/URL Loading System/NSURLCache problem
- From: Leon McNeill <email@hidden>
- Date: Mon, 14 Jul 2003 16:03:47 +0100
In the course of determining how I can exploit WebKit/WebFoundation,
I've been fiddling with the NSURLCache object. The cache itself works
for items added to the cache by the WebView et al (of course), but I
don't seem to have the full ability to insert my own items in the cache.
It works up until the last step, where the WebView ignores what I've
put in the cache and loads the web page from the live copy. Even with
the request's policy set to NSURLRequestReturnCacheDataDontLoad, the
WebView load still ignores the cache and I get
didFailLoadingWithError:"resource unavailable". Why is it that my own
cachedResponseForRequest:myRequest check works but asking the WebView
to load using the very same myRequest fails? It's as if WebViews
ignore the cache policy of the initial request, and always use
NSURLRequestUseProtocolCachePolicy internally. I realize that I could
tell the mainFrame to load
Data:MIMEType:encodingName:baseURL: or
loadHTMLString:baseURL:, but all of the images on the page will load
using NSURLRequestUseProtocolCachePolicy.
----
// Create a NSURLRequest:
NSURLRequest *myRequest = [[NSURLRequest alloc]
initWithURL:[NSURL URLWithString:@"
http://www.apple.com"]
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:60.0];
// Create your own NSCachedURLResponse and add it to the cache:
NSData *myData = ... // the HTML you wish to put in WebKit's cache as
'www.apple.com'
NSURLResponse *responseToCache = [[NSURLResponse alloc]
initWithURL:[NSURL URLWithString:@"
http://www.apple.com"]
MIMEType:@"text/html"
expectedContentLength:[myData length]
textEncodingName:nil];
NSCachedURLResponse *cachedResponse = [[NSCachedURLResponse alloc]
initWithResponse:responseToCache
data:myData];
[[NSURLCache sharedURLCache] storeCachedResponse:cachedResponse
forRequest:myRequest];
// Check if it's really there; I'm using myRequest again, but it can
just as easily be
// another NSURLRequest with the same URL and cache-friendly policy:
NSLog(@"cache=%@", [[NSURLCache sharedURLCache]
cachedResponseForRequest:myRequest]);
// Have your WebView load the web page using the initial request.
[[myWebView mainFrame] loadRequest:myRequest];
--
Leon McNeill (Beastie) email@hidden
http://www.lairware.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.