Handle app-background notification.

This commit is contained in:
Brent Simmons committed 2026-03-14 22:00:25 -07:00
1 parent 9cc400c3ec
commit 01c3671e4d
4 files changed
+24

No files matched your search

@@ -25,9 +25,14 @@ nonisolated final class DownloadCache: Sendable {
private let cache = Cache<DownloadCacheRecord>(timeToLive: 60 * 13, timeBetweenCleanups: 60 * 2)
init() {
NotificationCenter.default.addObserver(self, selector: #selector(handleAppDidGoToBackground(_:)), name: .appDidGoToBackground, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleLowMemory(_:)), name: .lowMemory, object: nil)
}
@objc func handleAppDidGoToBackground(_ notification: Notification) {
cache.removeAll()
}
@objc func handleLowMemory(_ notification: Notification) {
cache.removeAll()
}
@@ -24,9 +24,14 @@ nonisolated public final class HTMLMetadataDownloader: Sendable {
private let urlsReturning4xxsLock = OSAllocatedUnfairLock(initialState: Set<String>())
init() {
NotificationCenter.default.addObserver(self, selector: #selector(handleAppDidGoToBackground(_:)), name: .appDidGoToBackground, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleLowMemory(_:)), name: .lowMemory, object: nil)
}
@objc func handleAppDidGoToBackground(_ notification: Notification) {
cache.removeAll()
}
@objc func handleLowMemory(_ notification: Notification) {
cache.removeAll()
}
@@ -33,10 +33,19 @@ import RSParser
}()
init() {
NotificationCenter.default.addObserver(self, selector: #selector(handleAppDidGoToBackground(_:)), name: .appDidGoToBackground, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleLowMemory(_:)), name: .lowMemory, object: nil)
}
@objc func handleAppDidGoToBackground(_ notification: Notification) {
emptyCaches()
}
@objc func handleLowMemory(_ notification: Notification) {
emptyCaches()
}
private func emptyCaches() {
feedNameCache.removeAll()
titleCache.removeAll()
summaryCache.removeAll()
+5
View File
@@ -31,9 +31,14 @@ extension Notification.Name {
self.diskCache = BinaryDiskCache(folder: folder.path)
self.queue = DispatchQueue(label: "ImageDownloader serial queue - \(folder.path)")
NotificationCenter.default.addObserver(self, selector: #selector(handleAppDidGoToBackground(_:)), name: .appDidGoToBackground, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleLowMemory(_:)), name: .lowMemory, object: nil)
}
@objc func handleAppDidGoToBackground(_ notification: Notification) {
imageCache.removeAll()
}
@objc func handleLowMemory(_ notification: Notification) {
imageCache.removeAll()
}