@@ -43,19 +43,26 @@ protected class QueryInfo : ICachingInformation
4343 public QueryKey CacheKey { get ; }
4444 /// <inheritdoc />
4545 public bool CanGetFromCache { get ; }
46- /// <inheritdoc />
47- public bool CachePutRequired { get ; set ; }
4846 // Do not store but forward instead: Loader.ResultTypes can be null initially (if AutoDiscoverTypes
4947 // is enabled).
5048 /// <inheritdoc />
5149 public IType [ ] ResultTypes => Loader . ResultTypes ;
5250 /// <inheritdoc />
5351 public string QueryIdentifier => Loader . QueryIdentifier ;
52+ /// <inheritdoc />
53+ public bool IsResultFromCache { get ; private set ; }
5454 /// <summary>
55- /// Indicates if <see cref="Result"/> was obtained from the cache .
55+ /// The cache batcher to use for entities and collections puts .
5656 /// </summary>
57- public bool IsResultFromCache { get ; set ; }
57+ public CacheBatcher CacheBatcher { get ; private set ; }
5858
59+ /// <summary>
60+ /// Create a new <c>QueryInfo</c>.
61+ /// </summary>
62+ /// <param name="parameters">The query parameters.</param>
63+ /// <param name="loader">The loader.</param>
64+ /// <param name="querySpaces">The query spaces.</param>
65+ /// <param name="session">The session of the query.</param>
5966 public QueryInfo (
6067 QueryParameters parameters , Loader . Loader loader , ISet < string > querySpaces ,
6168 ISessionImplementor session )
@@ -71,6 +78,23 @@ public QueryInfo(
7178 CacheKey = Loader . GenerateQueryKey ( session , Parameters ) ;
7279 CanGetFromCache = Loader . CanGetFromCache ( session , Parameters ) ;
7380 }
81+
82+ /// <inheritdoc />
83+ public void SetCachedResult ( IList result )
84+ {
85+ if ( ! IsCacheable )
86+ throw new InvalidOperationException ( "Cannot set cached result on a non cacheable query" ) ;
87+ if ( Result != null )
88+ throw new InvalidOperationException ( "Result is already set" ) ;
89+ Result = result ;
90+ IsResultFromCache = result != null ;
91+ }
92+
93+ /// <inheritdoc />
94+ public void SetCacheBatcher ( CacheBatcher cacheBatcher )
95+ {
96+ CacheBatcher = cacheBatcher ;
97+ }
7498 }
7599
76100 protected abstract List < QueryInfo > GetQueryInformation ( ISessionImplementor session ) ;
@@ -105,26 +129,14 @@ public IEnumerable<string> GetQuerySpaces()
105129 }
106130
107131 /// <inheritdoc />
108- public IEnumerable < ISqlCommand > GetCommands ( IDictionary < ICachingInformation , IList > cachedResults )
132+ public IEnumerable < ISqlCommand > GetCommands ( )
109133 {
110134 ThrowIfNotInitialized ( ) ;
111135
112136 foreach ( var qi in _queryInfos )
113137 {
114- if ( qi . Loader . IsCacheable ( qi . Parameters ) )
115- {
116- var resultsFromCache = cachedResults [ qi ] ;
117-
118- if ( resultsFromCache != null )
119- {
120- // Cached results available, skip the command for them and stores them.
121- qi . Result = resultsFromCache ;
122- qi . IsResultFromCache = true ;
123- continue ;
124- }
125-
126- qi . CachePutRequired = true ;
127- }
138+ if ( qi . IsResultFromCache )
139+ continue ;
128140
129141 yield return qi . Loader . CreateSqlCommand ( qi . Parameters , Session ) ;
130142 }
@@ -238,15 +250,16 @@ public void ExecuteNonBatched()
238250 }
239251
240252 /// <inheritdoc />
241- public void InitializeEntitiesAndCollections ( DbDataReader reader , CacheBatcher cacheBatcher )
253+ public void InitializeEntitiesAndCollections ( DbDataReader reader )
242254 {
243255 for ( var i = 0 ; i < _queryInfos . Count ; i ++ )
244256 {
245257 var queryInfo = _queryInfos [ i ] ;
246258 if ( queryInfo . IsResultFromCache )
247259 continue ;
248260 queryInfo . Loader . InitializeEntitiesAndCollections (
249- _hydratedObjects [ i ] , reader , Session , queryInfo . Parameters . IsReadOnly ( Session ) , cacheBatcher ) ;
261+ _hydratedObjects [ i ] , reader , Session , queryInfo . Parameters . IsReadOnly ( Session ) ,
262+ queryInfo . CacheBatcher ) ;
250263 }
251264 }
252265
0 commit comments