aboutsummaryrefslogtreecommitdiff
path: root/Hutch/Networking/ResponseCache.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-03-17 23:19:43 -0500
committerChristian Cleberg <[email protected]>2026-03-17 23:19:43 -0500
commit32ad6cab8d58d99ebd8a28e8fa6e6f4e587cb1e5 (patch)
treeee36d421d704e508d5617d803b4c8cbdb4804fe1 /Hutch/Networking/ResponseCache.swift
parent8f2057c53e9009c2529c9c4849c914666c0e4b40 (diff)
downloadhutch-32ad6cab8d58d99ebd8a28e8fa6e6f4e587cb1e5.tar.gz
hutch-32ad6cab8d58d99ebd8a28e8fa6e6f4e587cb1e5.tar.bz2
hutch-32ad6cab8d58d99ebd8a28e8fa6e6f4e587cb1e5.zip
v1.0
Diffstat (limited to 'Hutch/Networking/ResponseCache.swift')
-rw-r--r--Hutch/Networking/ResponseCache.swift33
1 files changed, 33 insertions, 0 deletions
diff --git a/Hutch/Networking/ResponseCache.swift b/Hutch/Networking/ResponseCache.swift
new file mode 100644
index 0000000..a6cc269
--- /dev/null
+++ b/Hutch/Networking/ResponseCache.swift
@@ -0,0 +1,33 @@
+import Foundation
+import os
+
+/// Thread-safe in-memory cache for raw GraphQL response data.
+/// Keyed by a caller-provided string (typically service name + query hash).
+final class ResponseCache: Sendable {
+
+ private let storage: OSAllocatedUnfairLock<[String: Data]>
+
+ init() {
+ self.storage = OSAllocatedUnfairLock(initialState: [:])
+ }
+
+ /// Store raw response data under a cache key.
+ func set(_ data: Data, forKey key: String) {
+ storage.withLock { $0[key] = data }
+ }
+
+ /// Retrieve cached response data. Returns nil on cache miss.
+ func get(forKey key: String) -> Data? {
+ storage.withLock { $0[key] }
+ }
+
+ /// Remove a specific entry.
+ func remove(forKey key: String) {
+ storage.withLock { _ = $0.removeValue(forKey: key) }
+ }
+
+ /// Clear all cached data (e.g. on sign-out).
+ func clear() {
+ storage.withLock { $0.removeAll() }
+ }
+}