Handle low memory notification.

This commit is contained in:
Brent Simmons committed 2026-03-07 17:08:46 -08:00
1 parent dc27e85ed8
commit e2a7fd0051
1 file changed
+9
@@ -8,6 +8,7 @@
import Foundation
import os
import RSCore
import RSParser
// To get a notification when HTMLMetadata is cached, see HTMLMetadataCache.
@@ -22,6 +23,14 @@ nonisolated public final class HTMLMetadataDownloader: Sendable {
private let attemptDatesLock = OSAllocatedUnfairLock(initialState: [String: Date]())
private let urlsReturning4xxsLock = OSAllocatedUnfairLock(initialState: Set<String>())
init() {
NotificationCenter.default.addObserver(self, selector: #selector(handleLowMemory(_:)), name: .lowMemory, object: nil)
}
@objc func handleLowMemory(_ notification: Notification) {
cache.removeAll()
}
public func cachedMetadata(for url: String) -> RSHTMLMetadata? {
if Self.shouldSkipDownloadingMetadata(url) {
Self.logger.debug("HTMLMetadataDownloader: Skipping requested cached metadata for \(url)")