Installation
To install SwiftyCache, simply follow these steps:
- Open your Xcode project.
- In the menu, go to “File” > “Swift Packages” > “Add Package Dependency”.
- Enter the following repository URL:
https://github.com/examplerepository
- Click “Next” and select the latest version of SwiftyCache.
- Finally, click “Finish” to add the package to your project.
Alternatively, you can also manually integrate SwiftyCache into your project by downloading the source code from GitHub and linking it to your Xcode project.
Usage
To use SwiftyCache in your iOS application, follow these steps:
- Import the SwiftyCache module into your Swift file:
import SwiftyCache
- Create an instance of the
SwiftyCache
class:
let cache = SwiftyCache()
- Store data in the cache:
let dataToCache = Data() // Replace with your own data
cache.set(dataToCache, forKey: "myDataKey")
- Retrieve cached data:
if let cachedData = cache.get(forKey: "myDataKey") {
// Use the cached data
}
- You can also set an expiration time for the cached data:
cache.set(dataToCache, forKey: "myDataKey", expiration: .seconds(60)) // Cache expires after 60 seconds
- Clear the cache:
cache.clear()
Features
SwiftyCache offers the following features:
- Simple API: SwiftyCache provides a straightforward and easy-to-use API for cache management.
- In-Memory and Disk Caching: You can choose whether to cache data in memory or on disk, depending on your needs.
- Expiration Time: Define an expiration time for your cached data to automatically remove outdated entries.
- Thread-Safe: SwiftyCache ensures thread safety when accessing and modifying the cache.
- Customization: Customize the cache behavior by modifying various parameters such as cache size and eviction strategy.