AwesomeCache
AwesomeCache copied to clipboard
not triggering "cacheBlock" on API Caching
this is what i used code in my scenario.
let cache = try Cache<NSString>(name: "awesomeCache")
-> used as static
and i used below code for request to my api
cache.setObject(forKey: "name", cacheBlock: { success, failure in
// Perform tasks, e.g. call an API
self.user.autoComplete(self.url, params: string.encodedString(), headers: self.completeType == ` AutoCompleteType.LOCATION ? false:true) { (sent, json) in
success(json.stringValue, .Seconds(300))
}}
}, completion: { object, isLoadedFromCache, error in
if object {
print(object) // object is now cached
}
})
but its complete completion before trigger cacheBlock. Any one have idea whats going on this ?
Completion is also called if there is already a previously cached object. Are you sure there is no object called "name" in the cache already?
yeh im pretty sure. that's why i cant figure out any thing. :( can you give me full sample code for this thing. then i can find out is there something missing on my side.