Use this file to discover all available pages before exploring further.
PrismNetwork is the transport layer of the Prism SDK. It gives you a type-safe way to declare HTTP endpoints as Swift enums or structs, an actor-based LRU response cache, configurable retry policies, a GraphQL client, multipart upload with progress streaming, request deduplication, and an offline queue that flushes automatically when connectivity returns.
PrismResponseCache is an actor-based LRU cache with configurable capacity and per-entry TTL. It evicts the least-recently-used entry when the cache is full, and it automatically invalidates expired entries on access.
let cache = PrismResponseCache(maxSize: 200)// Store a response with a 10-minute TTLlet entry = PrismCacheEntry( data: responseData, statusCode: 200, headers: ["Content-Type": "application/json"], ttl: .seconds(600))await cache.set(entry, for: "GET:/v1/users?page=1")// Retrieve it (returns nil if expired or absent)if let cached = await cache.get(for: "GET:/v1/users?page=1") { // use cached.data}// Invalidate a specific key or the whole cacheawait cache.invalidate(key: "GET:/v1/users?page=1")await cache.clear()
Four cache policies give you fine-grained control:
Policy
Behaviour
.networkOnly
Always fetch from the network; ignore cached data
.cacheFirst
Return cached data if present; otherwise fetch
.cacheThenNetwork
Return cached data immediately, then revalidate
.staleWhileRevalidate
Serve stale data while revalidating in the background
PrismExponentialBackoff adds jitter (up to 0.5 s) to each delay to prevent thundering-herd scenarios. Both built-in policies conform to PrismRetryPolicy, so you can provide your own implementation.
PrismRequestDeduplicator coalesces identical in-flight requests. When multiple callers trigger the same endpoint at once, only one network call is made and all callers receive the same result.
PrismOfflineQueue stores requests when the device is offline and flushes them—in priority order—when connectivity is restored.
let queue = PrismOfflineQueue(autoFlush: true) { requests in for queued in requests { _ = try? await URLSession.shared.data(for: queued.urlRequest) }}// Enqueue a requestlet queued = PrismQueuedRequest(urlRequest: request, priority: 10)await queue.enqueue(queued)
Set autoFlush: true to let PrismConnectivityMonitor handle the flush automatically. You can also call dequeueAll() manually and process the requests yourself.
PrismMultipartFormData builds multipart/form-data bodies from Data parts and string fields. PrismUploadTask wraps a URLSession upload task and streams progress updates via AsyncStream.