AwesomeCache icon indicating copy to clipboard operation
AwesomeCache copied to clipboard

not triggering "cacheBlock" on API Caching

Open podiyaaa opened this issue 8 years ago • 2 comments

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 ?

podiyaaa avatar Nov 02 '16 04:11 podiyaaa

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?

aschuch avatar Nov 15 '16 21:11 aschuch

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.

podiyaaa avatar Nov 23 '16 11:11 podiyaaa