validTill property

  1. @override
DateTime get validTill

Defines till when the cache should be assumed to be valid.

Implementation

@override
DateTime get validTill {
  // Without a cache-control header we keep the file for a week
  var ageDuration = const Duration(days: 7);
  final controlHeader = _response.headers['cache-control']?.first;
  if (controlHeader != null) {
    final controlSettings = controlHeader.split(',');
    for (final setting in controlSettings) {
      final sanitizedSetting = setting.trim().toLowerCase();
      if (sanitizedSetting == 'no-cache') {
        ageDuration = const Duration();
      }
      if (sanitizedSetting.startsWith('max-age=')) {
        var validSeconds = int.tryParse(sanitizedSetting.split('=')[1]) ?? 0;
        if (validSeconds > 0) {
          ageDuration = Duration(seconds: validSeconds);
        }
      }
    }
  }

  return _receivedTime.add(ageDuration);
}