@@ -17,6 +17,7 @@ final class TagStorage {
1717 private let defaults = UserDefaults . standard
1818 private let encoder = JSONEncoder ( )
1919 private let decoder = JSONDecoder ( )
20+ private var cachedTags : [ ConnectionTag ] ?
2021
2122 private init ( ) {
2223 // Initialize with presets on first launch
@@ -29,16 +30,23 @@ final class TagStorage {
2930
3031 /// Load all tags (presets + custom)
3132 func loadTags( ) -> [ ConnectionTag ] {
33+ if let cached = cachedTags { return cached }
34+
3235 guard let data = defaults. data ( forKey: tagsKey) else {
33- return ConnectionTag . presets
36+ let tags = ConnectionTag . presets
37+ cachedTags = tags
38+ return tags
3439 }
3540
3641 do {
3742 let tags = try decoder. decode ( [ ConnectionTag ] . self, from: data)
43+ cachedTags = tags
3844 return tags
3945 } catch {
4046 Self . logger. error ( " Failed to load tags: \( error) " )
41- return ConnectionTag . presets
47+ let tags = ConnectionTag . presets
48+ cachedTags = tags
49+ return tags
4250 }
4351 }
4452
@@ -47,6 +55,7 @@ final class TagStorage {
4755 do {
4856 let data = try encoder. encode ( tags)
4957 defaults. set ( data, forKey: tagsKey)
58+ cachedTags = nil
5059 SyncChangeTracker . shared. markDirty ( . tag, ids: tags. map { $0. id. uuidString } )
5160 } catch {
5261 Self . logger. error ( " Failed to save tags: \( error) " )
0 commit comments