Empty the database articles cache when NetNewsWire moves to the background. This helps prevent the cache from growing forever.

This commit is contained in:
Brent Simmons 2019-10-12 15:06:21 -07:00
parent fae21082b0
commit 099172d9d2
5 changed files with 31 additions and 2 deletions

View File

@ -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> {

View File

@ -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) {

View File

@ -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

View File

@ -411,6 +411,14 @@ final class ArticlesTable: DatabaseTable {
}
}
}
// MARK: - Caches
func emptyCaches() {
queue.run { _ in
self.databaseArticlesCache = [String: DatabaseArticle]()
}
}
}
// MARK: - Private

View File

@ -224,9 +224,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
}
func applicationDidResignActive(_ notification: Notification) {
TimelineStringFormatter.emptyCaches()
AccountManager.shared.emptyCaches()
saveState()
}