Simplify image caching with PixieCacheKit.
PixieCacheKit offers advanced async/await integration for downloading images from URLs, intelligently storing them in either the File Manager for persistence or NSCache memory for quick access.
September 10, 2023 - v1.1.3
- Flexible Caching Options: Choose between memory-based caching or file-based caching, adapting to your app requirements.
- Cache Management Functions: Utilize built-in functions to manage cached data, including checking cache size and clearing cache when needed.
- Efficient Performance: Enhance app performance by optimizing image loading times.
- Simple Integration: Integrate PixieCacheKit seamlessly into your app with straight-forward setup.
- Smart Image Fetching: Intelligently fetch images, reducing network requests and improving loading times.
- Xcode 11 and above
- iOS 15 and above
To integrate PixieCacheKit into your project, you can use CocoaPods
or Swift Package Manager
.
Add the following line to your Podfile:
pod 'PixieCacheKit'
Then run pod install
to install the framework.
In Xcode, go to File -> Swift Packages -> Add Package Dependency and enter the repository URL:
https://github.com/aumChauhan/PixieCacheKit.git
- In SwiftUI App, first import the framework
import PixieCacheKit
, then configure your caching options usingPixieCacheKit.configure()
.
Example:
import SwiftUI
import PixieCacheKit
@main
struct MyApp: App {
init() {
// Configure to use a custom directory for file-based image caching.
PixieCacheKit.configure(directoryName: "MyAppCache", imageFormat: .jpeg)
// OR
// Use a specific memory limit for image caching.
PixieCacheKit.configure(memoryLimit: 100)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
The PixieImage
view simplifies image fetching, display, and caching in your iOS app. It provides two initializers to facilitate different use cases. This view takes an image URL and a cache key, allowing you to efficiently handle image data while benefiting from caching options.
PixieImage("https://example.com/image.jpg", cacheKey: "uniqueKey")
PixieImage("https://example.com/image.jpg", cacheKey: "uniqueKey") {
Text("Loading...") // Placeholder view
}
NOTE : You can enhance your
PixieImage
view by using SwiftUI view modifiers.
The PixieCacheManager
offers functions to manage cached data and retrieve cache-related information. This manager is designed to simplify cache management tasks and provide insights into your app's cached content.
Use the clearCacheData
function to remove all cached image data from the local cache directory.
PixieCacheManager.clearCacheData()
Retrieve the size of the cache directory using the getCacheDirectorySize
function.
let cacheSize = PixieCacheManager.getCacheDirectorySize()
PixieCacheKit provides a function to disable debug prints during the image downloading and retrieval process. This can help improve the clarity of your code and reduce unnecessary output in your app's logs.
struct MyApp: App {
init() {
PixieCacheKit.configure(directoryName: "MyAppCache", imageFormat: .jpeg)
// Disable debug prints
PixieCacheKit.disableDebugPrints()
}
}
PixieCacheKit is released under the MIT License.