Linked resources of large size are not cached when loading a page using NSURLRequest from an OSX App

javascript objective-c macos nsurlrequest nsurlcache

46 просмотра

1 ответ

My OSX app is attempting to load a web page inside a webview. I require caching the web page for the faster laoding of the page between successive launches of the app.

All the resource files(js/css/images) linked to the page is cached except one js file of 3MB size. I verified this in the cache.db file and no entry related to this particular file is present in the related table.

I have attempted many things, including

  • increasing the cache memory capacity
  • increasing timeout time for the request
  • changing parameters for cache policy

The workaround identified is to explicitly request the js file and forcefully store it in the cache.

[[NSURLCache sharedURLCache] storeCachedResponse:cachedURLResponse forRequest:request];

This will properly cache the file and on subsequent launches, there is only minimal network activity. This obviously is not a solution.

I'm not sure whether the file size matters, as i didn't find any reference related to size in NSURLCache documentation. One other observation is that the 'didFinishLoadForFrame' delegate is called before the linked resources are loaded.

Appreciate any help in this regard,



Автор: J. Thomas Источник Размещён: 08.11.2019 11:25

Ответы (1)

0 плюса

Yes, file size matters. The standard behavior of the cache is to not store anything that's larger than five or ten percent of the size of the cache. Increase the size of the cache to be at least two orders of magnitude bigger than what you're caching, and it will probably "just work".

If that isn't working, it probably indicates that the cache policy being sent back by the server for that one file disallows caching.

And if that isn't the problem, please update your question with the URL of the file that isn't being cached, and a code snippet showing how you configured the cache size.

Автор: dgatwood Размещён: 24.09.2016 07:40
Вопросы из категории :