Add canResume function that takes min and max limits.

This commit is contained in:
Brent Simmons committed 2026-03-16 16:54:27 -07:00
1 parent f1c37a2119
commit ad51fd4fbf
1 file changed
+10
@@ -22,6 +22,16 @@ nonisolated public struct CacheControlInfo: Codable, Equatable {
Date() >= resumeDate
}
/// canResume with a clamped maxAge — the actual maxAge
/// is clamped to [minMaxAge, maxMaxAge]. We do this because
/// sites tend to misconfigure their max age — we’ve seen
/// feeds that make this as long as one year, which is
/// clearly not intentional.
public func canResume(minMaxAge: TimeInterval, maxMaxAge: TimeInterval) -> Bool {
let clampedMaxAge = max(minMaxAge, min(maxMaxAge, maxAge))
return Date() >= dateCreated + clampedMaxAge
}
public init(dateCreated: Date, maxAge: TimeInterval) {
self.dateCreated = dateCreated
self.maxAge = maxAge