DataLoader 0.3.0

DataLoader 0.3.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release May 2019
SPMSupports SPM

Maintained by Luciano Almeida.



DataLoader

license Travis Codecov codebeat badge Twitter

This is a key/value memory cache convenience library for Swift.With DataLoader you can mantain your data loaded cached during an operation that sometimes requires you manage the state loaded and not loaded.

Inspired on the opensource facebook/dataloader library.

Instalation

Carthage

     github "LucianoPAlmeida/DataLoader" ~> 0.2.0  

CocoaPods

       pod 'DataLoader', '~> 0.2.0'     

Usage

   var loader: DataLoader<Int, Int>!
   // Creating the loader object.
   loader = DataLoader(loader: { (key, resolve, reject) in
       //load data from your source (can be a file, or a resource from server, or an heavy calculation)
       Fetcher.data(value: key, { (value, error) -> Void in 
           if let error = error {
               reject(error)
           } else {
               resolve(value)
           }
       })
   })
   
   //Using the loader object. 
   loader.load(key: 6) { (value, error) in
     //do your stuff with data
   }
   
   //Clear data from cache
   loader.cache.remove(key: 6) 
   
   or 
   
   loader.cache.clear()
   

Licence

DataLoader is released under the MIT License.