File tree Expand file tree Collapse file tree 2 files changed +23
-7
lines changed Expand file tree Collapse file tree 2 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -201,19 +201,21 @@ public class ApolloStore {
201
201
}
202
202
203
203
public class ReadTransaction {
204
- fileprivate let cache : any NormalizedCache
205
-
204
+ fileprivate let _cache : any NormalizedCache
205
+
206
+ public var readOnlyCache : any ReadOnlyNormalizedCache { _cache }
207
+
206
208
fileprivate lazy var loader : DataLoader < CacheKey , Record > = DataLoader { [ weak self] batchLoad in
207
209
guard let self else { return [ : ] }
208
- return try cache . loadRecords ( forKeys: batchLoad)
210
+ return try _cache . loadRecords ( forKeys: batchLoad)
209
211
}
210
212
211
213
fileprivate lazy var executor = GraphQLExecutor (
212
214
executionSource: CacheDataExecutionSource ( transaction: self )
213
215
)
214
216
215
217
fileprivate init ( store: ApolloStore ) {
216
- self . cache = store. cache
218
+ self . _cache = store. cache
217
219
}
218
220
219
221
public func read< Query: GraphQLQuery > ( query: Query ) throws -> Query . Data {
@@ -264,6 +266,8 @@ public class ApolloStore {
264
266
265
267
public final class ReadWriteTransaction : ReadTransaction {
266
268
269
+ public var cache : any NormalizedCache { _cache }
270
+
267
271
fileprivate var updateChangedKeysFunc : DidChangeKeysFunc ?
268
272
269
273
override init ( store: ApolloStore ) {
Original file line number Diff line number Diff line change 1
- public protocol NormalizedCache : AnyObject {
2
-
1
+ public protocol NormalizedCache : AnyObject , ReadOnlyNormalizedCache {
2
+
3
3
/// Loads records corresponding to the given keys.
4
4
///
5
5
/// - Parameters:
6
6
/// - key: The cache keys to load data for
7
7
/// - Returns: A dictionary of cache keys to records containing the records that have been found.
8
8
func loadRecords( forKeys keys: Set < CacheKey > ) throws -> [ CacheKey : Record ]
9
-
9
+
10
10
/// Merges a set of records into the cache.
11
11
///
12
12
/// - Parameters:
@@ -46,3 +46,15 @@ public protocol NormalizedCache: AnyObject {
46
46
/// Clears all records.
47
47
func clear( ) throws
48
48
}
49
+
50
+ /// A read-only view of a `NormalizedCache` for use within a `ReadTransaction`.
51
+ public protocol ReadOnlyNormalizedCache : AnyObject {
52
+
53
+ /// Loads records corresponding to the given keys.
54
+ ///
55
+ /// - Parameters:
56
+ /// - key: The cache keys to load data for
57
+ /// - Returns: A dictionary of cache keys to records containing the records that have been found.
58
+ func loadRecords( forKeys keys: Set < CacheKey > ) throws -> [ CacheKey : Record ]
59
+
60
+ }
You can’t perform that action at this time.
0 commit comments