Skip to content

Commit

Permalink
Delete cache in UserPreference
Browse files Browse the repository at this point in the history
  • Loading branch information
alfogrillo committed Apr 21, 2023
1 parent 1f6550b commit 7269f31
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions ElementX/Sources/Other/UserPreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,20 @@ protocol KeyedStorage<Value> {
/// phase is skipped, and values are stored natively in the plist.
final class UserDefaultsStorage<Value: Codable>: KeyedStorage {
private let userDefaults: UserDefaults
private var cache: [String: Value] = .init()

init(userDefaults: UserDefaults) {
self.userDefaults = userDefaults
}

subscript(key: String) -> Value? {
get {
guard cache[key] == nil else {
return cache[key]
}

let value: Value?
if Value.self is PlistRepresentable.Type {
value = decodePlistRepresentableValue(for: key)
} else {
value = decodeValue(for: key)
}

cache[key] = value
return value
}
set {
Expand All @@ -127,8 +121,6 @@ final class UserDefaultsStorage<Value: Codable>: KeyedStorage {
} else {
encode(value: newValue, for: key)
}

cache[key] = nil
}
}

Expand Down

0 comments on commit 7269f31

Please sign in to comment.