Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > WebView & Caching Problems

WebView & Caching Problems
Thread Tools
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
May 16, 2004, 04:00 PM
 
Hey guys,

I'm having a few problems with my WebView and caching the data. Basically, I have a HTML editor that has a WebView in it to preview the code. This WebView is updated automatically when a user types in the document text view, so it is essentially live.

For performance reasons, I would like to cache the images in the WebView, so images don't have to constantly reload when a user types.

So in this method:

Code:
- (NSURLRequest *)webView:(id)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(id)dataSource
I use this:

Code:
if ([[request URL] isEqualTo:baseURL]) { return request; } return [NSURLRequest requestWithURL:[request URL] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:[request timeoutInterval]];
The cache policy I chose seems to be the one I want, here is the description from Apple's docs:

Specifies that the existing cached data should be used to satisfy the request, regardless of its age or expiration date. If there is no existing data in the cache corresponding the request, the data is loaded from the originating source.
Now, with this I have two problems, firstly, images still reload when I type in my WebView, and secondly, because stylesheets are also being cached, so to activate the changes I make in a stylesheet I have to reopen the application and document. So I decided to use the manual refresh button to clear the cache, and thus load the contents from a fresh (which in theory, should get the newest stylesheet).

So in my refreshManual method:

Code:
NSURLCache *cache = [NSURLCache sharedURLCache]; [cache removeAllCachedResponses]; if (inWindowPreview) [[inWindowPreview mainFrame] loadHTMLString:html baseURL:baseURL];
So, with that, you'd think it would work. Well, it did, kind of. So I loaded up my document with stylesheet, and made changes to the stylesheet externally. I saved the stylesheet, then clicked the refreshManual button, the live preview successfully updated to the new stylesheet. I then made another change in the stylesheet, I then click refreshManual again, but it would not update again. I have no idea why this would work once but not again, since I am clicking the same button that clears out the cache.

If anyone can help with either problem (images not caching, and stylesheets caching) I'd be much appreciated,
Oliver
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
May 22, 2004, 05:20 PM
 
bump: noone knows anything about this?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:31 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2