Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not triggering "cacheBlock" on API Caching #95

Open
podiyaaa opened this issue Nov 2, 2016 · 2 comments
Open

not triggering "cacheBlock" on API Caching #95

podiyaaa opened this issue Nov 2, 2016 · 2 comments

Comments

@podiyaaa
Copy link

podiyaaa commented Nov 2, 2016

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 ?

@aschuch
Copy link
Owner

aschuch commented Nov 15, 2016

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?

@podiyaaa
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants