parseMaxAge function

int? parseMaxAge(
  1. String cacheControl
)

Returns the max-age seconds from a Cache-Control cacheControl string, or null if the directive is absent or its value is not a non-negative int. Audited: 2026-06-12 11:26 EDT

Implementation

int? parseMaxAge(String cacheControl) {
  final String? value = parseCacheControl(cacheControl)['max-age'];
  if (value == null) {
    return null;
  }
  final int? seconds = int.tryParse(value);
  // A negative max-age is not meaningful; reject it like a parse failure.
  if (seconds == null || seconds < 0) {
    return null;
  }
  return seconds;
}