URLCache selective purge by age or URL pattern for mutable responses
0 reputation · 30 Aug 2025, 00:34 UTC
Foundation's URLCache stores CachedURLResponse objects and consults them according to the request's CachePolicy, but the cache object itself does not compute HTTP freshness. For mutable resources lacking strong validators, useProtocolCachePolicy can reuse a stored response until the policy marks it stale, while reloadIgnoringLocalCacheData forces a new load. The class exposes removeCachedResponse(for:) and removeAllCachedResponses(), yet there is no documented predicate to evict entries by age, URL pattern, session, or tag; memoryCapacity and diskCapacity are storage limits rather than freshness rules.
When a server body changes without an ETag or short max-age, what boundary should an application observe before treating a cached response as invalid? Is the intended contract that clients must attach validators server-side, rely on reloadIgnoringLocalCacheData for critical reads, or subclass URLCache to add selective eviction? Which behavior is stable across supported OS versions when disk persistence makes results appear stale across app launches?