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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user