Add cache cleanup: age-based auto-eviction + manual Clear cache
CacheMaintenance prunes the SwiftData caches so they don't grow forever: seen markers >30d, read >90d, cached articles >30d, cached stories >14d — always protecting saved bookmarks. Runs on launch. Settings gains a "Clear offline cache" action (keeps saved) with a count + confirmation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -2,10 +2,15 @@
|
||||
// Jarvis — settings hub: Notifications, Connectivity, and server info.
|
||||
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
struct SettingsView: View {
|
||||
@EnvironmentObject var settings: ServerSettings
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Query private var cachedStories: [CachedStory]
|
||||
@Query private var cachedArticles: [CachedArticle]
|
||||
@State private var showClearConfirm = false
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
@@ -31,6 +36,14 @@ struct SettingsView: View {
|
||||
row(icon: "server.rack", title: settings.host ?? "Not configured",
|
||||
subtitle: "Connected server", chevron: false)
|
||||
}
|
||||
|
||||
group("STORAGE") {
|
||||
Button { showClearConfirm = true } label: {
|
||||
row(icon: "trash", title: "Clear offline cache",
|
||||
subtitle: "\(cachedStories.count) stories · \(cachedArticles.count) articles · keeps saved",
|
||||
chevron: false, tint: Color(hex: "C25555"))
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.vertical, 12)
|
||||
@@ -40,6 +53,12 @@ struct SettingsView: View {
|
||||
}
|
||||
.preferredColorScheme(.dark)
|
||||
.presentationDragIndicator(.visible)
|
||||
.confirmationDialog("Clear offline cache?", isPresented: $showClearConfirm, titleVisibility: .visible) {
|
||||
Button("Clear cache", role: .destructive) { CacheMaintenance.clear(modelContext) }
|
||||
Button("Cancel", role: .cancel) {}
|
||||
} message: {
|
||||
Text("Removes cached stories, articles, and read/seen history. Your saved stories are kept.")
|
||||
}
|
||||
}
|
||||
|
||||
private var header: some View {
|
||||
@@ -64,11 +83,13 @@ struct SettingsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func row(icon: String, title: String, subtitle: String, chevron: Bool = true) -> some View {
|
||||
private func row(icon: String, title: String, subtitle: String,
|
||||
chevron: Bool = true, tint: Color = .white) -> some View {
|
||||
HStack(spacing: 14) {
|
||||
Image(systemName: icon).font(.system(size: 18)).foregroundStyle(Color(hex: "999999")).frame(width: 26)
|
||||
Image(systemName: icon).font(.system(size: 18))
|
||||
.foregroundStyle(tint == .white ? Color(hex: "999999") : tint).frame(width: 26)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(title).font(.system(size: 16, weight: .heavy)).foregroundStyle(.white).lineLimit(1)
|
||||
Text(title).font(.system(size: 16, weight: .heavy)).foregroundStyle(tint).lineLimit(1)
|
||||
Text(subtitle).font(.system(size: 12)).foregroundStyle(Color(hex: "888888")).lineLimit(1)
|
||||
}
|
||||
Spacer()
|
||||
|
||||
Reference in New Issue
Block a user