# swiftui-cached-async-image **Repository Path**: jon/swiftui-cached-async-image ## Basic Information - **Project Name**: swiftui-cached-async-image - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-03-04 - **Last Updated**: 2024-09-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SwiftUI CachedAsyncImage πŸ—ƒοΈ `CachedAsyncImage` is `AsyncImage`, but with cache capabilities. ## Usage `CachedAsyncImage` has the exact same API and behavior as `AsyncImage`, so you just have to change this: ```swift AsyncImage(url: logoURL) ``` to this: ```swift CachedAsyncImage(url: logoURL) ``` In addition to `AsyncImage` initializers, you have the possibilities to specify the cache you want to use (by default `URLCache.shared` is used), and to use `URLRequest` instead of `URL`: ```swift CachedAsyncImage(urlRequest: logoURLRequest, urlCache: .imageCache) ``` ```swift // URLCache+imageCache.swift extension URLCache { static let imageCache = URLCache(memoryCapacity: 512_000_000, diskCapacity: 10_000_000_000) } ``` Remember when setting the cache the response (in this case our image) must be no larger than about 5% of the disk cache (See [this discussion](https://developer.apple.com/documentation/foundation/nsurlsessiondatadelegate/1411612-urlsession#discussion)). ## Installation 1. In Xcode, open your project and navigate to **File** β†’ **Swift Packages** β†’ **Add Package Dependency...** 2. Paste the repository URL (`https://github.com/lorenzofiamingo/swiftui-cached-async-image`) and click **Next**. 3. Click **Finish**. ## Other projects [SwiftUI AsyncButton πŸ–²οΈ](https://github.com/lorenzofiamingo/swiftui-async-button) [SwiftUI MapItemPicker πŸ—ΊοΈ](https://github.com/lorenzofiamingo/swiftui-map-item-picker) [SwiftUI PhotosPicker πŸŒ‡](https://github.com/lorenzofiamingo/swiftui-photos-picker) [SwiftUI VerticalTabView πŸ”](https://github.com/lorenzofiamingo/swiftui-vertical-tab-view) [SwiftUI SharedObject 🍱](https://github.com/lorenzofiamingo/swiftui-shared-object)