File tree Expand file tree Collapse file tree
Application/DevLogPersistence/Sources/Cache Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,30 +9,25 @@ import Foundation
99import DevLogData
1010
1111final class MemoryCacheStoreImpl : MemoryCacheStore {
12- private let queue = DispatchQueue (
13- label: " devlog.memory-cache-store " ,
14- qos: . utility
15- )
16- private var values = [ String: Data] ( )
12+ private let lock = NSLock ( )
13+ private var values = [ String: Any] ( )
1714
1815 func value< T: Codable > ( forKey key: String ) -> T ? {
19- queue. sync {
20- let decoder = JSONDecoder ( )
21- guard let data = self . values [ key] else { return nil }
22- return try ? decoder. decode ( T . self, from: data)
23- }
16+ lock. lock ( )
17+ defer { lock. unlock ( ) }
18+
19+ return values [ key] as? T
2420 }
2521
2622 func setValue< T: Codable > ( _ value: T ? , forKey key: String ) {
27- queue. sync {
28- let encoder = JSONEncoder ( )
29- guard let value else {
30- self . values. removeValue ( forKey: key)
31- return
32- }
23+ lock. lock ( )
24+ defer { lock. unlock ( ) }
3325
34- guard let data = try ? encoder. encode ( value) else { return }
35- self . values [ key] = data
26+ guard let value else {
27+ values. removeValue ( forKey: key)
28+ return
3629 }
30+
31+ values [ key] = value
3732 }
3833}
You can’t perform that action at this time.
0 commit comments