Background
I'm building an app that links recent web pages you've visited together.
To do this, I need to get the HTML for recent URLs using Cocoa.
Right now, I'm using an invisible WebView to do this.
As I understand it, if the URL isn't in the cache for my app, this is hitting web servers.
What I want
The chances are high that the URL I'm grabbing has already been cached by Safari as the page has already been visited.
I want my app to check Safari's cache for the URL first. If it's there, it should just use this data. If not, it should hit the web server and store the page in my app's cache.
I don't really want to have to parse the cache.db file from Safari using sqlite3 - I've no idea if this format will stay the same. I'm after something simpler and more high level.
What I've tried
I know that you can set up your own NSURLCache using the method initWithMemoryCapacity:diskCapacity:diskPath:
but I don't want to try pointing this to the Safari cache in case it screws up Safari by writing to it.
Is there an easy, high level way of sharing the Safari cache?
UPDATE
Aha. I've just realised there may be a way to do this I've been missing.
I could make a new instance of NSURLCache
with initWithMemoryCapacity:diskCapacity:diskPath:
, point it at the Safari cache, then specify a cache policy of NSURLRequestReturnCacheDataDontLoad
for the URL Request when loading the page.
When this fails, I could just try and load the page as normal. I'll try this out and update the question when I know more.