Skip to content

Commit 0f8ab1e

Browse files
committed
refactor: 메모리 캐싱으로 대체
1 parent c1fb461 commit 0f8ab1e

7 files changed

Lines changed: 17 additions & 65 deletions

Application/DevLogData/Sources/DataAssembler.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class DataAssembler: Assembler {
4040
TodoRepositoryImpl(
4141
todoService: container.resolve(TodoService.self),
4242
todoCategoryService: container.resolve(TodoCategoryService.self),
43-
store: container.resolve(UserDefaultsStore.self),
43+
store: container.resolve(MemoryCacheStore.self),
4444
widgetSyncEventBus: container.resolve(WidgetSyncEventBus.self),
4545
todoMutationEventBus: container.resolve(TodoMutationEventBus.self)
4646
)
@@ -53,15 +53,15 @@ public final class DataAssembler: Assembler {
5353
container.register(TodoCategoryRepository.self) {
5454
TodoCategoryRepositoryImpl(
5555
todoCategoryService: container.resolve(TodoCategoryService.self),
56-
store: container.resolve(UserDefaultsStore.self)
56+
store: container.resolve(MemoryCacheStore.self)
5757
)
5858
}
5959

6060
container.register(AuthSessionRepository.self) {
6161
AuthSessionRepositoryImpl(
6262
authService: container.resolve(AuthService.self),
6363
todoCategoryService: container.resolve(TodoCategoryService.self),
64-
store: container.resolve(UserDefaultsStore.self),
64+
store: container.resolve(MemoryCacheStore.self),
6565
provider: container.resolve(AuthSessionStateProvider.self)
6666
)
6767
}
@@ -104,7 +104,7 @@ public final class DataAssembler: Assembler {
104104
PushNotificationRepositoryImpl(
105105
pushNotificationService: container.resolve(PushNotificationService.self),
106106
todoCategoryService: container.resolve(TodoCategoryService.self),
107-
store: container.resolve(UserDefaultsStore.self)
107+
store: container.resolve(MemoryCacheStore.self)
108108
)
109109
}
110110

Application/DevLogData/Sources/Repository/AuthSessionRepositoryImpl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ final class AuthSessionRepositoryImpl: AuthSessionRepository {
1515

1616
private let authService: AuthService
1717
private let todoCategoryService: TodoCategoryService
18-
private let store: UserDefaultsStore
18+
private let store: MemoryCacheStore
1919
private let provider: AuthSessionStateProvider
2020

2121
init(
2222
authService: AuthService,
2323
todoCategoryService: TodoCategoryService,
24-
store: UserDefaultsStore,
24+
store: MemoryCacheStore,
2525
provider: AuthSessionStateProvider
2626
) {
2727
self.authService = authService

Application/DevLogData/Sources/Repository/PushNotificationRepositoryImpl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ final class PushNotificationRepositoryImpl: PushNotificationRepository {
1717

1818
private let pushNotificationService: PushNotificationService
1919
private let todoCategoryService: TodoCategoryService
20-
private let store: UserDefaultsStore
20+
private let store: MemoryCacheStore
2121

2222
init(
2323
pushNotificationService: PushNotificationService,
2424
todoCategoryService: TodoCategoryService,
25-
store: UserDefaultsStore
25+
store: MemoryCacheStore
2626
) {
2727
self.pushNotificationService = pushNotificationService
2828
self.todoCategoryService = todoCategoryService

Application/DevLogData/Sources/Repository/TodoCategoryRepositoryImpl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ final class TodoCategoryRepositoryImpl: TodoCategoryRepository {
1313
}
1414

1515
private let todoCategoryService: TodoCategoryService
16-
private let store: UserDefaultsStore
16+
private let store: MemoryCacheStore
1717

1818
init(
1919
todoCategoryService: TodoCategoryService,
20-
store: UserDefaultsStore
20+
store: MemoryCacheStore
2121
) {
2222
self.todoCategoryService = todoCategoryService
2323
self.store = store

Application/DevLogData/Sources/Repository/TodoRepositoryImpl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ final class TodoRepositoryImpl: TodoRepository {
1616

1717
private let todoService: TodoService
1818
private let todoCategoryService: TodoCategoryService
19-
private let store: UserDefaultsStore
19+
private let store: MemoryCacheStore
2020
private let widgetSyncEventBus: WidgetSyncEventBus
2121
private let todoMutationEventBus: TodoMutationEventBus
2222

2323
init(
2424
todoService: TodoService,
2525
todoCategoryService: TodoCategoryService,
26-
store: UserDefaultsStore,
26+
store: MemoryCacheStore,
2727
widgetSyncEventBus: WidgetSyncEventBus,
2828
todoMutationEventBus: TodoMutationEventBus
2929
) {

Application/DevLogData/Tests/Repository/AuthSessionRepositoryImplTests.swift

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct AuthSessionRepositoryImplTests {
2020
let preference = makePreferenceResponse()
2121
let authService = AuthSessionAuthServiceSpy()
2222
let todoCategoryService = AuthSessionTodoCategoryServiceSpy(preferences: [preference])
23-
let store = AuthSessionUserDefaultsStoreSpy()
23+
let store = AuthSessionMemoryCacheStoreSpy()
2424
let provider = AuthSessionStateProviderSpy()
2525
let repository = AuthSessionRepositoryImpl(
2626
authService: authService,
@@ -48,7 +48,7 @@ struct AuthSessionRepositoryImplTests {
4848
let preference = makePreferenceResponse()
4949
let authService = AuthSessionAuthServiceSpy(isSignedIn: true)
5050
let todoCategoryService = AuthSessionTodoCategoryServiceSpy(preferences: [preference])
51-
let store = AuthSessionUserDefaultsStoreSpy()
51+
let store = AuthSessionMemoryCacheStoreSpy()
5252
let provider = AuthSessionStateProviderSpy()
5353
store.setValue([preference], forKey: Key.preferences)
5454
let repository = AuthSessionRepositoryImpl(
@@ -153,7 +153,7 @@ private actor AuthSessionTodoCategoryServiceSpy: TodoCategoryService {
153153
}
154154
}
155155

156-
private final class AuthSessionUserDefaultsStoreSpy: UserDefaultsStore {
156+
private final class AuthSessionMemoryCacheStoreSpy: MemoryCacheStore {
157157
private var values = [String: Data]()
158158

159159
func value<T: Codable>(forKey key: String) -> T? {
@@ -172,28 +172,4 @@ private final class AuthSessionUserDefaultsStoreSpy: UserDefaultsStore {
172172

173173
values[key] = try? JSONEncoder().encode(value)
174174
}
175-
176-
func removeValues(withPrefix prefix: String) {
177-
values.keys
178-
.filter { $0.hasPrefix(prefix) }
179-
.forEach { values.removeValue(forKey: $0) }
180-
}
181-
182-
func string(forKey key: String) -> String? {
183-
nil
184-
}
185-
186-
func setString(_ value: String?, forKey key: String) { }
187-
188-
func stringArray(forKey key: String) -> [String] {
189-
[]
190-
}
191-
192-
func setStringArray(_ value: [String], forKey key: String) { }
193-
194-
func bool(forKey key: String) -> Bool {
195-
false
196-
}
197-
198-
func setBool(_ value: Bool, forKey key: String) { }
199175
}

Application/DevLogData/Tests/Repository/TodoRepositoryImplTests.swift

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct TodoRepositoryImplTests {
6565
private func makeFixture() -> Fixture {
6666
let todoService = TodoServiceSpy()
6767
let todoCategoryService = TodoCategoryServiceSpy()
68-
let store = TodoRepositoryUserDefaultsStoreSpy()
68+
let store = TodoRepositoryMemoryCacheStoreSpy()
6969
let widgetSyncEventBus = WidgetSyncEventBusSpy()
7070
let todoMutationEventBus = TodoMutationEventBusSpy()
7171
let repository = TodoRepositoryImpl(
@@ -159,7 +159,7 @@ private struct TodoCategoryServiceSpy: TodoCategoryService {
159159
}
160160
}
161161

162-
private final class TodoRepositoryUserDefaultsStoreSpy: UserDefaultsStore {
162+
private final class TodoRepositoryMemoryCacheStoreSpy: MemoryCacheStore {
163163
private var values = [String: Any]()
164164

165165
func value<T: Codable>(forKey key: String) -> T? {
@@ -174,30 +174,6 @@ private final class TodoRepositoryUserDefaultsStoreSpy: UserDefaultsStore {
174174

175175
values[key] = value
176176
}
177-
178-
func removeValues(withPrefix prefix: String) {
179-
values.keys
180-
.filter { $0.hasPrefix(prefix) }
181-
.forEach { values.removeValue(forKey: $0) }
182-
}
183-
184-
func string(forKey key: String) -> String? {
185-
nil
186-
}
187-
188-
func setString(_ value: String?, forKey key: String) { }
189-
190-
func stringArray(forKey key: String) -> [String] {
191-
[]
192-
}
193-
194-
func setStringArray(_ value: [String], forKey key: String) { }
195-
196-
func bool(forKey key: String) -> Bool {
197-
false
198-
}
199-
200-
func setBool(_ value: Bool, forKey key: String) { }
201177
}
202178

203179
private final class WidgetSyncEventBusSpy: WidgetSyncEventBus {

0 commit comments

Comments
 (0)