init: init proj
This commit is contained in:
24
DDYSClient/Services/ContentCache.swift
Normal file
24
DDYSClient/Services/ContentCache.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user