Empty the database articles cache when NetNewsWire moves to the background. This helps prevent the cache from growing forever.
This commit is contained in:
parent
fae21082b0
commit
099172d9d2
@ -615,6 +615,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
}
|
||||
}
|
||||
|
||||
/// Empty caches that can reasonably be emptied. Call when the app goes in the background, for instance.
|
||||
func emptyCaches() {
|
||||
database.emptyCaches()
|
||||
}
|
||||
|
||||
// MARK: - Container
|
||||
|
||||
public func flattenedFeeds() -> Set<Feed> {
|
||||
|
@ -223,6 +223,15 @@ public final class AccountManager: UnreadCountProvider {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Caches
|
||||
|
||||
/// Empty caches that can reasonably be emptied — when the app moves to the background, for instance.
|
||||
public func emptyCaches() {
|
||||
for account in accounts {
|
||||
account.emptyCaches()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
@objc dynamic func unreadCountDidChange(_ notification: Notification) {
|
||||
|
@ -143,6 +143,14 @@ public final class ArticlesDatabase {
|
||||
public func mark(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) -> Set<ArticleStatus>? {
|
||||
return articlesTable.mark(articles, statusKey, flag)
|
||||
}
|
||||
|
||||
// MARK: - Caches
|
||||
|
||||
/// Call to free up some memory. Should be done when the app is backgrounded, for instance.
|
||||
/// This does not empty *all* caches — just the ones that are empty-able.
|
||||
public func emptyCaches() {
|
||||
articlesTable.emptyCaches()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
@ -411,6 +411,14 @@ final class ArticlesTable: DatabaseTable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Caches
|
||||
|
||||
func emptyCaches() {
|
||||
queue.run { _ in
|
||||
self.databaseArticlesCache = [String: DatabaseArticle]()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
@ -224,9 +224,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
||||
}
|
||||
|
||||
func applicationDidResignActive(_ notification: Notification) {
|
||||
|
||||
TimelineStringFormatter.emptyCaches()
|
||||
|
||||
AccountManager.shared.emptyCaches()
|
||||
saveState()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user