Configure caching for queries
mainGraph.Client provides an opt-in caching layer for query operations to reduce bandwidth and latency.
Note: Caching is not available for mutation operations or any requests that provide a retryHandler.
Cache Policies
.cacheOnly: Fetch from cache only. Returns error if not found..networkOnly: Fetch from network only. Ignores cache..cacheFirst(expireIn: Int): Check cache first. If missing or older thanexpireIn, fetch from network..networkFirst(expireIn: Int): Fetch from network first. If network fails and cache is not older thanexpireIn, return cached data.
Usage
You can enable caching client-wide by setting the cachePolicy property on the Graph.Client instance, or override it for a specific request using the cachePolicy parameter in queryGraphWith.
// Client-wide caching
let client = Graph.Client(shopDomain: "...", apiKey: "...")
client.cachePolicy = .cacheFirst
// Per-request override
let task = client.queryGraphWith(query, cachePolicy: .networkFirst(expireIn: 20)) { query, error in
// ...
}