From ad51fd4fbfa32c8f8149e309e05b30b1ffb6db21 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 16 Mar 2026 16:54:27 -0700 Subject: [PATCH] Add canResume function that takes min and max limits. --- Modules/RSWeb/Sources/RSWeb/CacheControlInfo.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Modules/RSWeb/Sources/RSWeb/CacheControlInfo.swift b/Modules/RSWeb/Sources/RSWeb/CacheControlInfo.swift index a8453e899..6fd52be96 100644 --- a/Modules/RSWeb/Sources/RSWeb/CacheControlInfo.swift +++ b/Modules/RSWeb/Sources/RSWeb/CacheControlInfo.swift @@ -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