pod 'ObjectMapperCacheManager'
When store something to a device, "key" is the only identifier, just like UserDefaults in Foundation.
UserDefaults.standard.setValue(["name":"James","age":16], forKey:"User")But, the difference between UserDefaults and CacheManager is the directory in sandbox:
UserDefaults: Home/Library/Preference/CacheManager: Home/Library/Caches
The data could be a dict or an array
letdict:[String:Any]=["name":"James","age":16]CacheManager.setCache(json: dict, for:"Json")letdictArray=[[String: Any]]=[dict]CacheManager.setCache(json: dictArray, for:"JsonArray")// must declare the type
iflet dict:[String:Any]=CacheManager.cacheJson(for:"Json")as?[String:Any]{print(dict)}iflet array:[[String:Any]]=CacheManager.cacheJson(for:"JsonArray")as?[String:Any]{print(array)}The only requirement is that the object must conform to ObjectMapper's Mappable protocol.
letuser:User=User()CacheManager.setCache(object: user, for:"Object")letuserList=[user]CacheManager.setCache(array: userList, for:"ObjectArray")iflet user:User=CacheManager.cache(for:"Object"){}iflet array:[User]=CacheManager.cacheArray(for:"ObjectArray"){}ObjectMapperCacheManager is released under an MIT license. See LICENSE for more information.
