From 798f46fbb1b39262d6e0ce95a131101dad4db958 Mon Sep 17 00:00:00 2001 From: Robin Kutesa Date: Sat, 20 Jun 2026 14:31:52 +0300 Subject: [PATCH] Align cache eviction to the backend aging model Retention now mirrors the backend: cached stories age out at RECENT_HOURS (72h, the active feed window), seen/read markers at 96h (window + buffer), and cached article bodies at 14 days (raw-article retention). Saved bookmarks stay protected. Co-Authored-By: Claude Opus 4.8 --- Jarvis/Store/CacheMaintenance.swift | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Jarvis/Store/CacheMaintenance.swift b/Jarvis/Store/CacheMaintenance.swift index 5fa884d..00b894b 100644 --- a/Jarvis/Store/CacheMaintenance.swift +++ b/Jarvis/Store/CacheMaintenance.swift @@ -7,21 +7,23 @@ import SwiftData @MainActor enum CacheMaintenance { + private static let hour: TimeInterval = 3_600 private static let day: TimeInterval = 86_400 - // Retention windows. - private static let seenDays = 30.0 // "seen" markers: only useful while a story is live - private static let readDays = 90.0 // read history: small, keep longer - private static let articleDays = 30.0 // offline article bodies - private static let storyDays = 14.0 // offline story list + // Aligned to the backend's aging model: + // RECENT_HOURS = 72 → active feed window; drop cached stories past it + // raw-article retention ~14 days → match for cached article bodies + private static let recentHours = 72.0 // backend active window (story list) + private static let markerHours = 96.0 // seen/read markers: active window + buffer + private static let articleDays = 14.0 // cached article bodies (backend article retention) /// Age-based eviction. Run on launch. Cheap; protects saved stories. static func prune(_ context: ModelContext) { let now = Date() - let seenCutoff = now.addingTimeInterval(-seenDays * day) - let readCutoff = now.addingTimeInterval(-readDays * day) + let seenCutoff = now.addingTimeInterval(-markerHours * hour) + let readCutoff = now.addingTimeInterval(-markerHours * hour) let articleCutoff = now.addingTimeInterval(-articleDays * day) - let storyCutoff = now.addingTimeInterval(-storyDays * day) + let storyCutoff = now.addingTimeInterval(-recentHours * hour) // Markers: simple age batch deletes. try? context.delete(model: SeenStory.self, where: #Predicate { $0.seenAt < seenCutoff })