A simple data caching framework based on Realm database.
- Add data with one line of code.
- Set expiry time and framework will automatically delete data after expiry time.
- Set disk usage limit and framework will automatically delete old files.
- Set auto delete property to let framework delete a data only on your instruction.
- Works on devices supporting iOS 10.0+
PopupDialog is available through CocoaPods. Simply add the following to your Podfile:
use_frameworks!
target '<Your Target Name>'
pod 'AnyDataCache'
Following code can be used to save data into disk -
DataCache.sharedInstance.addData(dataKey: dataKey, data: data, expiryDate: someDateorNil, autoDelete: true, onAdd: nil)DataKey can be a URL or things like Social Identity (like facebook graph user id). 'N' is a swift 'Data' object. Additionaly you can also pass optional args like expiry date, auto delete flag, on task finish closure to this function.
To read back saved data, you can use following code -
// if you saved a string as data into DataCache, then this is how you retrieve it.
// Response comes back on main thread after read operation completes on background thread.
DataCache.sharedInstance.getData(dataKey: dataKey) { [weak self] anyData in
if let messageData = anyData?.data {
if let message = String(data: messageData, encoding: .utf8) {
print("Your saved message is : \(message)")
}
}
}To set disk usage limit
DataCache.sharedInstance.setStorageLimitInMB(20) // 20 MBVijayendra Tripathi, Founder @ Baselabs LLP To follow on Twitter: @vijayendra_t
AnyDataCache is available under the MIT license. See the LICENSE file for more info.
Floppy icon: Icons made by Flat Icons from www.flaticon.com
Orbiton Font - https://fonts.google.com/specimen/Orbitron
