Closed alexookah closed 6 years ago
EVURLCache does take into account the header variables Cache-Control
and Pragma
when caching a response. So if you want to control is server side, you could set one of these. You do have to make sure that you did not set EVURLCache.IGNORE_CACHE_CONTROL to true. Otherwise the headers will be ignored.
You could also arrange saving the response inside your app. If you want to filter out specific requests from being cashed, you could arrange that in your app by using a filter like this:
EVURLCache.filter { request in
if request.url?.host == "githubbadge.appspot.com" {
return false
}
return true
}
I tried many ways to modify the response headers but it seems EVURL was not respecting that.
i ended up using. the EVURLCache.MAX_AGE = "60". which seems to do my job.
i only found that when the cache is not expired and i do reloadIgnoringCacheData. should the response be cached if the content is not the same with the cached content?
In the storeCachedResponse there is a mechanism that even if it should not cache but the file is already in the preCache, it will still save it so that you will have the latest version if the next request will use another cache policy
in the log you will see a message that starts with: CACHE file in PreCache folder, overriding
Great thanks. Is it ok if i use EVURLCache.MAX_AGE = "60". rather than configuring the Cache-Control from the API?
Sure you can. By default EVURLCache will use the Access-Control-Max-Age header field and when that's empty it will use the MAX_AGE like this:
let maxAge: String = request.value(forHTTPHeaderField: "Access-Control-Max-Age") ?? EVURLCache.MAX_AGE
is there a difference between Access-Control-Max-Age and Cache-Control:max-age in EVURLCache?
EVURLCache only uses Access-Control-Max-Age For the Cache-Control parameter it will only use the no-store and no-cache values. Do you think it should also consider the max-age parameter? But then you could have situations where these 2 are different. So what to do then?
For more info about these 2 can be found at: https://stackoverflow.com/questions/40731465/access-control-max-age-vs-cache-control
So i guess the Cache-Control:max-age doesnt make any difference for EVURLCache ? is it handled in Alamofire request ?
I would be surprised if Alamofire did something with the Cache-Control:max-age header
Hi,
i am trying to modify the header of the response. and i was looking inside the library maybe there was a way to add an option to Modify or add a Cache-Control header?