How to disable cache in URLSession.shared.data in SwiftUI

All I have come across are NSURLSession. Is this possible for URLSession? How?

I noticed my requests show up instantly so I figured these reponses are cached instead of fetching new ones.

Caching should not be the default. Weird why it was set this way.

Thoughts?

This is my code. It is basic

let url = URL(string: urlLink)!
let (data, _) = try await URLSession.shared.data(from: url)
print(String(decoding: data, as: UTF8.self))

Create a new URLSession as follows:

URLSession(configuration: .ephemeral)

And then use that session in your code

How to disable cache in URLSession.shared.data in SwiftUI
 
 
Q