@@ -106,8 +106,7 @@ private async Task ExecuteBatchedAsync(CancellationToken cancellationToken)
106106 stopWatch . Start ( ) ;
107107 }
108108
109- var querySpaces = new HashSet < string > (
110- _queries . SelectMany ( q => q . QueryInformation ) . SelectMany ( qi => qi . QuerySpaces ) ) ;
109+ var querySpaces = new HashSet < string > ( _queries . SelectMany ( q => q . GetQuerySpaces ( ) ) ) ;
111110 if ( querySpaces . Count > 0 )
112111 {
113112 // The auto-flush must be handled before obtaining the commands, because an auto-flush
@@ -169,22 +168,16 @@ private async Task ExecuteBatchedAsync(CancellationToken cancellationToken)
169168 }
170169 }
171170
172- private async Task < IDictionary < IQueryInformation , IList > > GetCachedResultsAsync ( CancellationToken cancellationToken )
171+ private async Task < IDictionary < ICachingInformation , IList > > GetCachedResultsAsync ( CancellationToken cancellationToken )
173172 {
174173 cancellationToken . ThrowIfCancellationRequested ( ) ;
175- var resultByQueryInfo = new Dictionary < IQueryInformation , IList > ( ) ;
174+ var resultByQueryInfo = new Dictionary < ICachingInformation , IList > ( ) ;
176175 var statisticsEnabled = Session . Factory . Statistics . IsStatisticsEnabled ;
177- var queriesByCaches =
178- _queries
179- . SelectMany ( q => q . QueryInformation )
180- . Where ( q => q . Loader . IsCacheable ( q . Parameters ) && q . Loader . CanGetFromCache ( Session , q . Parameters ) )
181- . GroupBy (
182- q => Session . Factory . GetQueryCache ( q . Parameters . CacheRegion ) ,
183- ( cache , q ) => new { cache , queryInfos = q } ) ;
184-
176+ var queriesByCaches = GetQueriesByCaches ( ci => ci . CanGetFromCache ) ;
185177 foreach ( var queriesByCache in queriesByCaches )
186178 {
187- var queryInfos = queriesByCache . queryInfos . ToArray ( ) ;
179+ var queryInfos = queriesByCache . ToArray ( ) ;
180+ var cache = queriesByCache . Key ;
188181 var keys = new QueryKey [ queryInfos . Length ] ;
189182 var parameters = new QueryParameters [ queryInfos . Length ] ;
190183 var returnTypes = new ICacheAssembler [ queryInfos . Length ] [ ] ;
@@ -196,26 +189,26 @@ private async Task<IDictionary<IQueryInformation, IList>> GetCachedResultsAsync(
196189 parameters [ i ] = queryInfo . Parameters ;
197190 returnTypes [ i ] = queryInfo . Parameters . HasAutoDiscoverScalarTypes
198191 ? null
199- : queryInfo . CacheKey . ResultTransformer . GetCachedResultTypes ( queryInfo . Loader . ResultTypes ) ;
192+ : queryInfo . CacheKey . ResultTransformer . GetCachedResultTypes ( queryInfo . ResultTypes ) ;
200193 spaces [ i ] = queryInfo . QuerySpaces ;
201194 }
202195
203- var results = await ( queriesByCache . cache . GetManyAsync ( keys , parameters , returnTypes , spaces , Session , cancellationToken ) ) . ConfigureAwait ( false ) ;
196+ var results = await ( cache . GetManyAsync ( keys , parameters , returnTypes , spaces , Session , cancellationToken ) ) . ConfigureAwait ( false ) ;
204197
205198 for ( var i = 0 ; i < queryInfos . Length ; i ++ )
206199 {
207200 resultByQueryInfo . Add ( queryInfos [ i ] , results [ i ] ) ;
208201
209202 if ( statisticsEnabled )
210203 {
211- var queryIdentifier = queryInfos [ i ] . Loader . QueryIdentifier ;
204+ var queryIdentifier = queryInfos [ i ] . QueryIdentifier ;
212205 if ( results [ i ] == null )
213206 {
214- Session . Factory . StatisticsImplementor . QueryCacheMiss ( queryIdentifier , queriesByCache . cache . RegionName ) ;
207+ Session . Factory . StatisticsImplementor . QueryCacheMiss ( queryIdentifier , cache . RegionName ) ;
215208 }
216209 else
217210 {
218- Session . Factory . StatisticsImplementor . QueryCacheHit ( queryIdentifier , queriesByCache . cache . RegionName ) ;
211+ Session . Factory . StatisticsImplementor . QueryCacheHit ( queryIdentifier , cache . RegionName ) ;
219212 }
220213 }
221214 }
@@ -231,17 +224,11 @@ private async Task PutCacheableResultsAsync(CancellationToken cancellationToken)
231224 return ;
232225
233226 var statisticsEnabled = Session . Factory . Statistics . IsStatisticsEnabled ;
234- var queriesByCaches =
235- _queries
236- . SelectMany ( q => q . QueryInformation )
237- . Where ( q => q . CachePutRequired )
238- . GroupBy (
239- q => Session . Factory . GetQueryCache ( q . Parameters . CacheRegion ) ,
240- ( cache , q ) => new { cache , queryInfos = q } ) ;
241-
227+ var queriesByCaches = GetQueriesByCaches ( ci => ci . CachePutRequired ) ;
242228 foreach ( var queriesByCache in queriesByCaches )
243229 {
244- var queryInfos = queriesByCache . queryInfos . ToArray ( ) ;
230+ var queryInfos = queriesByCache . ToArray ( ) ;
231+ var cache = queriesByCache . Key ;
245232 var keys = new QueryKey [ queryInfos . Length ] ;
246233 var parameters = new QueryParameters [ queryInfos . Length ] ;
247234 var returnTypes = new ICacheAssembler [ queryInfos . Length ] [ ] ;
@@ -251,11 +238,11 @@ private async Task PutCacheableResultsAsync(CancellationToken cancellationToken)
251238 var queryInfo = queryInfos [ i ] ;
252239 keys [ i ] = queryInfo . CacheKey ;
253240 parameters [ i ] = queryInfo . Parameters ;
254- returnTypes [ i ] = queryInfo . CacheKey . ResultTransformer . GetCachedResultTypes ( queryInfo . Loader . ResultTypes ) ;
241+ returnTypes [ i ] = queryInfo . CacheKey . ResultTransformer . GetCachedResultTypes ( queryInfo . ResultTypes ) ;
255242 results [ i ] = queryInfo . Result ;
256243 }
257244
258- var putted = await ( queriesByCache . cache . PutManyAsync ( keys , parameters , returnTypes , results , Session , cancellationToken ) ) . ConfigureAwait ( false ) ;
245+ var putted = await ( cache . PutManyAsync ( keys , parameters , returnTypes , results , Session , cancellationToken ) ) . ConfigureAwait ( false ) ;
259246
260247 if ( ! statisticsEnabled )
261248 continue ;
@@ -265,7 +252,7 @@ private async Task PutCacheableResultsAsync(CancellationToken cancellationToken)
265252 if ( putted [ i ] )
266253 {
267254 Session . Factory . StatisticsImplementor . QueryCachePut (
268- queryInfos [ i ] . Loader . QueryIdentifier , queriesByCache . cache . RegionName ) ;
255+ queryInfos [ i ] . QueryIdentifier , cache . RegionName ) ;
269256 }
270257 }
271258 }
0 commit comments