[webkit-dev] WebKit caching

Adam Thorsen adam.thorsen at gmail.com
Sat Apr 11 18:54:18 PDT 2009


Darin,

Thanks for this detailed response!  I've put together a demo app that  
implements techniques A, B, and C. You can find it here: http://github.com/awt/cachedemo/tree/master 
.
  Unfortunately javascript files are still being cached.  You can  
reproduce this by pointing the browser at a local web server serving a  
simple html file that includes a javascript file.  Before loading the  
page, however, make sure that the javascript file hasn't been modified  
for a significant period of time (let's say an hour to be safe).  Once  
the page is loaded and you have verified that your js code is  
executing as expected, modify the js code in such a way that reloading  
the page should show the change.  Once the page is reloaded, your  
change should not be reflected.  Looking at the console, you'll see  
the response headers for each resource requested (like this):

2009-04-11 12:54:46.753 CacheDemo[8364:10b] response for path:/ 
javascripts/yui_custom/interpreter.js
{
     Connection = close;
     "Content-Length" = 758;
     "Content-Type" = "text/javascript";
     Date = "Sat, 11 Apr 2009 19:53:03 GMT";
     Etag = "\"49e0bad7-2f6-4d4424\"";
     "Last-Modified" = "Sat, 11 Apr 2009 15:44:23 GMT";
}

I also noticed recently that there is a "Disable Caches" option under  
the Develop menu on Safari.  I tested it using the same procedure and  
it indeed did not cache the javascript, so I know this is possible one  
way or another.

Thanks again for the response,

-Adam

On Apr 10, 2009, at 3:01 PM, Darin Adler wrote:

> There are three different caches involved in WebKit on Mac OS X.
>
>    A) The resource cache in the NSURL networking layer, which caches  
> both in memory and on disk.
>    B) The resource cache inside WebCore, which caches in memory.
>    C) The page cache in WebCore, a higher level cache which only  
> affects "go back" and "go forward" commands.
>
>> 1.  Overriding the NSURLCache cachedResponseForRequest and  
>> cachedResponse forRequest methods
>
> To turn off cache (A) you can call:
>
>    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
>    [[NSURLCache sharedURLCache] setDiskCapacity:0];
>
>>   WebPreferences *prefs = [webView preferences];
>>   [prefs setUsesPageCache:NO];
>
> The code above turns off cache (C).
>
> One way to turn off cache (B) is to do this:
>
>    [prefs setCacheModel:WebCacheModelDocumentViewer]
>
> I suggest giving that a try.
>
>    -- Darin
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090411/749dabbe/attachment.html>


More information about the webkit-dev mailing list