Browse Questions
  • The library removes cipher-level mistakes but not key-management or operational ones, and those are where real integrations fail.
  • Encrypt mode makes the payload unreadable to anyone but the named peer and also proves its origin, while sign/verify mode leaves the payload in the clear and only proves who produced it and that…
  • TLS protects the connection, not the message — it ends at the first thing that terminates it, which may be a load balancer, a logging proxy, or an attacker's intercepting certificate on a…
  • URLCache stores responses from network requests in memory and/or on disk.

Answer: URLCache stores responses from network requests in memory and/or on disk. It respects HTTP cache headers (Cache-Control, ETag, Expires) automatically.

Code Example:

// Configure a larger cache at app startup
URLCache.shared = URLCache(
    memoryCapacity: 50 * 1024 * 1024,  // 50MB memory
    diskCapacity: 200 * 1024 * 1024,   // 200MB disk
    directory: nil
)

// Control caching per request
var request = URLRequest(url: url)
request.cachePolicy = .returnCacheDataElseLoad  // use cache, fall back to network

// Cache policies:
// .useProtocolCachePolicy     — default, follows HTTP headers
// .reloadIgnoringLocalCache   — always hits network
// .returnCacheDataElseLoad    — use cache, only fetch if not cached
// .returnCacheDataDontLoad    — only use cache, never fetch (offline mode)

// Manually store a response
let cachedResponse = CachedURLResponse(response: response, data: data)
URLCache.shared.storeCachedResponse(cachedResponse, for: request)