0

Looking for some insight on if this is possible or not. I am trying preload my NSURLCache with a Cache.DB that is already filled with caches from a uiwebview. I don't see why this can't be possible since the Apple documentation states that the diskPath:

"In iOS, path is the name of a subdirectory of the application’s default cache directory in which to store the on-disk cache (the subdirectory is created if it does not exist)."

So what I did was copy the whole Cache folder as a referenced folder to my application bundle and used the path in the code below. However, I am unable to pull the caches. The path location to the cache files is correct as I printed it out.. Any idea?

Also please don't mention EVURLCache I already looked into that.

NSString *cacheDir = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Caches"

NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024
                                                     diskCapacity:20 * 1024 * 1024
                                                         diskPath:cacheDir;

[NSURLCache setSharedURLCache:URLCache];
sudo
  • 1,648
  • 1
  • 20
  • 22

1 Answers1

0

override NSURLCache and set yours as the default cache. web views honour this and your class can obviously be 'pre filled' or rather get resources locally

no preloading needed.

Plus you don't mess with 'private file formats/ disk layout' / folder structure'

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • will this approach prohibit any further caching for other non-related items beyond the ones you wanted to "preload" ? Meaning, if we use this to "preload" certain things, will it still be able to cache other things in other webviews etc? thanks – zonabi Sep 22 '15 at 16:48
  • 1
    Before setting your subclass as shared cache. Save the old and depending on the webview set and reset the shared cache – Daij-Djan Sep 23 '15 at 07:29
  • Thank you. similar question: will it prevent caching of other things in the *same* webview? – zonabi Sep 24 '15 at 16:19
  • what you'd ideally do is implement your NSURLCache subclass to forward all requests to super if you can't handle it. that way it is a drop in replacement – Daij-Djan Sep 24 '15 at 16:21
  • no resetting the shared cache. just use it and add an additional functionality to it (if you want :)) – Daij-Djan Sep 24 '15 at 16:22