func fetch()

in Sources/XCRemoteCache/Network/CachedNetworkClient.swift [43:60]


    func fetch(_ url: URL, completion: @escaping (Result<Data, NetworkClientError>) -> Void) {
        let localURL = localURLBuilder.location(for: url)
        if fileManager.fileExists(atPath: localURL.path), let data = fileManager.contents(atPath: localURL.path) {
            completion(.success(data))
            return
        }
        client.fetch(url) { [fileManager] result in
            completion(result)
            guard case .success(let data) = result else {
                return
            }
            do {
                try fileManager.spt_writeToFile(atPath: localURL.path, contents: data)
            } catch {
                errorLog("Saving to cache location failed with error: \(error)")
            }
        }
    }