Closed mario-madrid closed 1 year ago
Cache-Control
is not enough to cache a response.
You should provide Date
header in the response to make it work. This is needed to compare it with the freshness of the response, in your case max-age
.
What I could do in such case, need to confirm this, is to check cache response date (added by the interceptor) to workaround this.
Yes, is what I've done. Once I add by another interceptor the header last-modified, it caches correctly. My responses has the "Date" header, but the cache is simply ignored because the method _hasCacheDirectives only checks for etag and last-modified header.
We can see this in cache_strategy.dart lines 140-149. I paste them in this comment:
bool _hasCacheDirectives(Response response) {
if (_enforceResponseCachable()) {
return true;
}
var result = response.headers[etagHeader] != null;
result |= response.headers[lastModifiedHeader] != null;
return result;
}
Fixed in 3.4.2
Thank you so much, It was really fast! :)
Hello.
Thank you for the amazing library.
This issue https://github.com/llfbandit/dio_cache_interceptor/issues/14 is happening again. It was resolved on this commit (https://github.com/llfbandit/dio_cache_interceptor/commit/283ba28d7e0c24b25dd77fcc497ca1aa75cdd65c) but is happening again with the changes done on this commit (https://github.com/llfbandit/dio_cache_interceptor/commit/300d31ef405bdfd46f54efe6e6986acf2b6e4058#diff-64d31cdb5c921267241ca3b129a926e65686a33f36c8e393776643f70dd38867).
In summary, we are only able to cache if the header ETag or last-modified is present with cache-control. It is not suppose to work like this, as mentioned in the issue linked. We should be able to cache without this headers.
Thank you!