mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-02 02:22:25 +00:00
Handle low memory notification.
This commit is contained in:
1 parent
b080735211
commit
a760d30cd3
1 file changed
+14
-5
@@ -9,6 +9,7 @@
|
||||
import Foundation
|
||||
import Account
|
||||
import Articles
|
||||
import RSCore
|
||||
|
||||
@MainActor final class IconImageCache {
|
||||
|
||||
@@ -20,6 +21,14 @@ import Articles
|
||||
private var smallIconImageCache = [SidebarItemIdentifier: IconImage]()
|
||||
private var authorIconImageCache = [Author: IconImage]()
|
||||
|
||||
init() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(handleLowMemory(_:)), name: .lowMemory, object: nil)
|
||||
}
|
||||
|
||||
@objc func handleLowMemory(_ notification: Notification) {
|
||||
emptyCache()
|
||||
}
|
||||
|
||||
func imageFor(_ feedID: SidebarItemIdentifier) -> IconImage? {
|
||||
if let smartFeed = SmartFeedsController.shared.find(by: feedID) {
|
||||
return imageForFeed(smartFeed)
|
||||
@@ -59,11 +68,11 @@ import Articles
|
||||
}
|
||||
|
||||
func emptyCache() {
|
||||
smartFeedIconImageCache = [SidebarItemIdentifier: IconImage]()
|
||||
feedIconImageCache = [SidebarItemIdentifier: IconImage]()
|
||||
faviconImageCache = [SidebarItemIdentifier: IconImage]()
|
||||
smallIconImageCache = [SidebarItemIdentifier: IconImage]()
|
||||
authorIconImageCache = [Author: IconImage]()
|
||||
smartFeedIconImageCache.removeAll()
|
||||
feedIconImageCache.removeAll()
|
||||
faviconImageCache.removeAll()
|
||||
smallIconImageCache.removeAll()
|
||||
authorIconImageCache.removeAll()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user