title: How can I add caching to AsyncImage
body: <p>I'm new to SwiftUI and was looking how to download images from a URL. I've found out that in iOS15 you can use AsyncImage to handle all the phases of an Image. The code looks like this.</p>
  <pre><code>    AsyncImage(url: URL(string: urlString)) { phase in
          switch phase {
          case .success(let image):
              image
                  .someModifers
          case .empty:
              Image(systemName: &quot;Placeholder Image&quot;)
                  .someModifers
          case .failure(_):
              Image(systemName: &quot;Error Image&quot;)
                  .someModifers
          @unknown default:
              Image(systemName: &quot;Placeholder Image&quot;)
                  .someModifers
          }
      }
  </code></pre>
  <p>I would launch my app and every time I would scroll up &amp; down on my List, it would download the images again. So how would I be able to add a cache. I was trying to add a cache the way I did in Swift. Something like this.</p>
  <pre><code>struct DummyStruct {
    var imageCache = NSCache&lt;NSString, UIImage&gt;()
    func downloadImageFromURLString(_ urlString: String) {
      guard let url = URL(string: urlString) else { return }
      URLSession.shared.dataTask(with: url) { data, response, error in
          if let _ = error {
              fatalError()
          }
          
          guard let data = data, let image = UIImage(data: data) else { return }
          imageCache.setObject(image, forKey: NSString(string: urlString))
      }
      .resume()
    }
  }
  </code></pre>
  <p>But it didn't go to good. So I was wondering is there a way to add caching to AsyncImage? Thanks would appreciate any help.</p>