Closed cliffordh closed 4 years ago
Hi, Thanks for your advice. This sounds good, I'll think about it in the next release. Thank you again.
It's supported in 0.2.4
// buildCacheOptions:
options: buildServiceCacheOptions()
// or: set maxAge null or don't set it.
options: buildConfigurableCacheOptions()
only if maxAge == null, it will try to get maxAge and maxStale from response headers. And if maxStale is setted before, it'll not be overrided by header's value.
@hurshi How to define "reverted" behavior, i.e. always take maxAge and maxStale from response headers as primary, and only if they are not provided by the service then use passed "fallback" maxAge and maxStale? Should CacheConfig.defaultMaxAge and defaultMaxStale be used in such case?
@hurshi Currently defaultMaxAge is not working, because DioCacheManager method has to be fixed:
Future<bool> _pushToCache(Response response) {
RequestOptions options = response.request;
Duration maxAge = options.extra[DIO_CACHE_KEY_MAX_AGE];
Duration maxStale = options.extra[DIO_CACHE_KEY_MAX_STALE];
if (null == maxAge) {
_tryParseHead(response, maxStale, (_maxAge, _maxStale) {
maxAge = _maxAge;
maxStale = _maxStale;
});
}
// FIX
if (null == maxAge) {
maxAge = _manager?._config.defaultMaxAge;
maxStale = _manager?._config.defaultMaxStale;
}
// End of FIX
if (null == maxAge) return Future.value(false);
There are multiple cache control headers sent as part of an HTTP response. It would be nice if cache expiration was controlled by those headers by default, and then override using the existing mechanisms.