Skip to content

Commit 6e6c75a

Browse files
committed
Added cachedValue public methods for multiplexers
1 parent d1799c5 commit 6e6c75a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

AsyncMux/Sources/Multiplexer.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,17 @@ public final class Multiplexer<T: Codable & Sendable>: MuxRepositoryProtocol {
9494
}
9595
}
9696

97-
/// Returns the value currently cached in memory
98-
public private(set) var storedValue: T?
97+
/// Returns the value currently stored in memory or on disk, ignoring the TTL
98+
public var cachedValue: T? {
99+
storedValue ?? cacheKey.flatMap {
100+
MuxCacher.load(domain: MuxRootDomain, key: $0, type: T.self)
101+
}
102+
}
99103

100104

101105
// Private part
102106

107+
internal private(set) var storedValue: T? // exposed for MultiplexerMap
103108
private let cacheKey: String?
104109
private let onFetch: OnFetch
105110

AsyncMux/Sources/MultiplexerMap.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,9 @@ public final class MultiplexerMap<K: MuxKey, T: Codable & Sendable>: MuxReposito
108108
(muxMap[key] ?? createMux(for: key)).store(value: value)
109109
}
110110

111-
/// Returns the value currently cached in memory
112-
public func storedValue(for key: K) -> T? {
113-
muxMap[key].flatMap { mux in
114-
!mux.isExpired ? mux.storedValue : nil
115-
}
111+
/// Returns the value currently stored in memory or on disk, ignoring the TTL
112+
public func cachedValue(for key: K) -> T? {
113+
muxMap[key]?.cachedValue
116114
}
117115

118116

@@ -130,4 +128,10 @@ public final class MultiplexerMap<K: MuxKey, T: Codable & Sendable>: MuxReposito
130128
muxMap[key] = mux
131129
return mux
132130
}
131+
132+
internal func storedValue(for key: K) -> T? { // exposed for MultiRequester
133+
muxMap[key].flatMap { mux in
134+
!mux.isExpired ? mux.storedValue : nil
135+
}
136+
}
133137
}

0 commit comments

Comments
 (0)