Re: 'Global' NSURLCache?
Re: 'Global' NSURLCache?
- Subject: Re: 'Global' NSURLCache?
- From: "Quinn \"The Eskimo!\"" <email@hidden>
- Date: Tue, 31 Oct 2017 08:29:44 +0000
On 28 Oct 2017, at 03:11, email@hidden wrote:
> I'd like to understand the reasoning behind making NSHTTPStorage globally
> available to all apps vs. NSURLCache being per-app only.
To start, the cookie store is not global, it’s per user. That level of sharing
is grandfathered in from the very early days of NSURLConnection, which was
really just the back end of Safari factored out for everyone to use. At the
time it made sense for Safari and all the user’s apps to share a cookie store.
These days, of course, that policy is considered security madness. Across all
of our platforms the only apps that share Safari’s cookie store are non-MAS
apps on the Mac. Everything else has its own cookie store (although they can
share cookie stores via App Groups).
As to the difference between the cookie store and the cache, I suspect that’s
an artefact of the implementation. Back in the day both were stored as simple
files on disk. Obviously it’s a pain to coordinate shared access to such
files. Doing this for cookies was considered important, so the implementers
came up with a (clunky) scheme for that. Doing it for the cache wasn’t
important — and it’s much harder due to the expected access patterns for the
cache — so the caches were left separate.
On modern systems the cookie store and cache are actually managed by a
<x-man-page://8/nsurlstoraged>, so this coordination is much easier. This is
what enables, for example, each App Group to have a shared cookie store.
If you want to share a cache between processes you may be able to do that by
having them both initialise an NSURLCache instance to point to the same place
on disk (using `-initWithMemoryCapacity:diskCapacity:diskPath:`). I /think/
that’ll work but I haven’t looked into it in detail so I’m not 100% sure.
If you need a definitive answer to the last point I recommend that you open a
DTS tech support incident for it. That’ll allow me to spend time researching
it properly.
<https://developer.apple.com/support/technical/>
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden