Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/react-native-nitro-fetch/ios/FetchCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,24 @@ final class FetchCache {

static func getResultIfFresh(_ key: String, maxAgeMs: Int64) -> NitroResponse? {
var out: NitroResponse?
var shouldEvict = false
queue.sync {
if let entry = results[key] {
let age = Int64(Date().timeIntervalSince1970 * 1000) - entry.timestampMs
if age <= maxAgeMs {
out = entry.response
} else {
results.removeValue(forKey: key)
shouldEvict = true
}
}
}
if shouldEvict {
queue.async(flags: .barrier) {
if let entry = results[key] {
let age = Int64(Date().timeIntervalSince1970 * 1000) - entry.timestampMs
if age > maxAgeMs {
results.removeValue(forKey: key)
}
}
}
}
Expand Down
Loading