Skip to content

Commit cf36028

Browse files
fixup! Replace ICache interface by a CacheBase class
Add missing cleanup
1 parent e3f6bc9 commit cf36028

File tree

2 files changed

+21
-42
lines changed

2 files changed

+21
-42
lines changed

src/NHibernate/Async/Engine/BatchFetchQueue.cs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async Task<bool> CheckCacheAndProcessResultAsync()
133133
return false;
134134
}
135135

136-
async Task<bool> ProcessKeyAsync(KeyValuePair<CollectionEntry, IPersistentCollection> me, bool ignoreCache = false)
136+
Task<bool> ProcessKeyAsync(KeyValuePair<CollectionEntry, IPersistentCollection> me, bool ignoreCache = false)
137137
{
138138
var ce = me.Key;
139139
var collection = me.Value;
@@ -144,18 +144,18 @@ async Task<bool> ProcessKeyAsync(KeyValuePair<CollectionEntry, IPersistentCollec
144144
// and CollectionEntry.AfterAction())
145145
// though we clear the queue on flush, it seems like a good idea to guard
146146
// against potentially null LoadedKey:s
147-
return false;
147+
return Task.FromResult<bool>(false);
148148
}
149149

150150
if (collection.WasInitialized)
151151
{
152152
log.Warn("Encountered initialized collection in BatchFetchQueue, this should not happen.");
153-
return false;
153+
return Task.FromResult<bool>(false);
154154
}
155155

156156
if (checkForEnd && (index >= keyIndex.Value + batchSize || index == map.Count))
157157
{
158-
return true;
158+
return Task.FromResult<bool>(true);
159159
}
160160
if (collectionPersister.KeyType.IsEqual(id, ce.LoadedKey, collectionPersister.Factory))
161161
{
@@ -170,17 +170,17 @@ async Task<bool> ProcessKeyAsync(KeyValuePair<CollectionEntry, IPersistentCollec
170170
if (!keyIndex.HasValue || index < keyIndex.Value)
171171
{
172172
collectionKeys.Add(new KeyValuePair<KeyValuePair<CollectionEntry, IPersistentCollection>, int>(me, index));
173-
return false;
173+
return Task.FromResult<bool>(false);
174174
}
175175

176-
if (!checkCache || !await (IsCachedAsync(ce.LoadedKey, collectionPersister, cancellationToken)).ConfigureAwait(false))
176+
// No need to check "!checkCache || !IsCached(ce.LoadedKey, collectionPersister)":
177+
// "batchableCache == null" already means there is no cache, so IsCached can only yield false.
178+
// (This method is now removed.)
179+
if (collectionEntries != null)
177180
{
178-
if (collectionEntries != null)
179-
{
180-
collectionEntries[i] = ce;
181-
}
182-
keys[i++] = ce.LoadedKey;
181+
collectionEntries[i] = ce;
183182
}
183+
keys[i++] = ce.LoadedKey;
184184
}
185185
else if (ignoreCache)
186186
{
@@ -197,20 +197,20 @@ async Task<bool> ProcessKeyAsync(KeyValuePair<CollectionEntry, IPersistentCollec
197197
// that are after the demanded key.
198198
if (!keyIndex.HasValue || index < keyIndex.Value + batchSize)
199199
{
200-
return false;
200+
return Task.FromResult<bool>(false);
201201
}
202-
return await (CheckCacheAndProcessResultAsync()).ConfigureAwait(false);
202+
return CheckCacheAndProcessResultAsync();
203203
}
204204
if (i == batchSize)
205205
{
206206
i = 1; // End of array, start filling again from start
207207
if (keyIndex.HasValue)
208208
{
209209
checkForEnd = true;
210-
return index >= keyIndex.Value + batchSize || index == map.Count;
210+
return Task.FromResult<bool>(index >= keyIndex.Value + batchSize || index == map.Count);
211211
}
212212
}
213-
return false;
213+
return Task.FromResult<bool>(false);
214214
}
215215
}
216216

@@ -378,17 +378,6 @@ Task<bool> ProcessKeyAsync(EntityKey key, bool ignoreCache = false)
378378
}
379379
}
380380

381-
private async Task<bool> IsCachedAsync(object collectionKey, ICollectionPersister persister, CancellationToken cancellationToken)
382-
{
383-
cancellationToken.ThrowIfCancellationRequested();
384-
if (persister.HasCache && context.Session.CacheMode.HasFlag(CacheMode.Get))
385-
{
386-
CacheKey cacheKey = context.Session.GenerateCacheKey(collectionKey, persister.KeyType, persister.Role);
387-
return await (persister.Cache.Cache.GetAsync(cacheKey, cancellationToken)).ConfigureAwait(false) != null;
388-
}
389-
return false;
390-
}
391-
392381
/// <summary>
393382
/// Checks whether the given entity key indexes are cached.
394383
/// </summary>

src/NHibernate/Engine/BatchFetchQueue.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,14 @@ bool ProcessKey(KeyValuePair<CollectionEntry, IPersistentCollection> me, bool ig
342342
return false;
343343
}
344344

345-
if (!checkCache || !IsCached(ce.LoadedKey, collectionPersister))
345+
// No need to check "!checkCache || !IsCached(ce.LoadedKey, collectionPersister)":
346+
// "batchableCache == null" already means there is no cache, so IsCached can only yield false.
347+
// (This method is now removed.)
348+
if (collectionEntries != null)
346349
{
347-
if (collectionEntries != null)
348-
{
349-
collectionEntries[i] = ce;
350-
}
351-
keys[i++] = ce.LoadedKey;
350+
collectionEntries[i] = ce;
352351
}
352+
keys[i++] = ce.LoadedKey;
353353
}
354354
else if (ignoreCache)
355355
{
@@ -538,16 +538,6 @@ bool ProcessKey(EntityKey key, bool ignoreCache = false)
538538
}
539539
}
540540

541-
private bool IsCached(object collectionKey, ICollectionPersister persister)
542-
{
543-
if (persister.HasCache && context.Session.CacheMode.HasFlag(CacheMode.Get))
544-
{
545-
CacheKey cacheKey = context.Session.GenerateCacheKey(collectionKey, persister.KeyType, persister.Role);
546-
return persister.Cache.Cache.Get(cacheKey) != null;
547-
}
548-
return false;
549-
}
550-
551541
/// <summary>
552542
/// Checks whether the given entity key indexes are cached.
553543
/// </summary>

0 commit comments

Comments
 (0)