Files
ddys-client/DDYSClient/Services/ContentCache.swift
2026-02-26 22:15:35 +08:00

25 lines
529 B
Swift

import Foundation
@Observable
final class ContentCache {
static let shared = ContentCache()
private var timestamps: [String: Date] = [:]
private let ttl: TimeInterval = 300 // 5
private init() {}
func isExpired(key: String) -> Bool {
guard let ts = timestamps[key] else { return true }
return Date().timeIntervalSince(ts) > ttl
}
func markFresh(key: String) {
timestamps[key] = Date()
}
func invalidate(key: String) {
timestamps[key] = nil
}
}