File tree Expand file tree Collapse file tree
DevLogData/Sources/Protocol
DevLogPersistence/Sources Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //
2+ // MemoryCacheStore.swift
3+ // DevLogData
4+ //
5+ // Created by opfic on 6/9/26.
6+ //
7+
8+ import Foundation
9+
10+ public protocol MemoryCacheStore {
11+ func value< T: Codable > ( forKey key: String ) -> T ?
12+ func setValue< T: Codable > ( _ value: T ? , forKey key: String )
13+ }
Original file line number Diff line number Diff line change 1+ //
2+ // MemoryCacheStoreImpl.swift
3+ // DevLogPersistence
4+ //
5+ // Created by opfic on 6/9/26.
6+ //
7+
8+ import Foundation
9+ import DevLogData
10+
11+ final class MemoryCacheStoreImpl : MemoryCacheStore {
12+ private let queue = DispatchQueue (
13+ label: " devlog.memory-cache-store " ,
14+ qos: . utility
15+ )
16+ private var values = [ String: Data] ( )
17+
18+ 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+ }
24+ }
25+
26+ 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+ }
33+
34+ guard let data = try ? encoder. encode ( value) else { return }
35+ self . values [ key] = data
36+ }
37+ }
38+ }
Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ public final class PersistenceAssembler: Assembler {
1717 UserDefaultsStoreImpl ( )
1818 }
1919
20+ container. register ( MemoryCacheStore . self) {
21+ MemoryCacheStoreImpl ( )
22+ }
23+
2024 container. register ( ThemeStore . self) {
2125 ThemeStoreImpl ( )
2226 }
You can’t perform that action at this time.
0 commit comments