/// <summary> /// Checks whether the given collection key indexes are cached. /// </summary> /// <param name="collectionKeys">The list of pairs of collection entries and their indexes.</param> /// <param name="keyIndexes">The array of indexes of <paramref name="collectionKeys"/> that have to be checked.</param> /// <param name="persister">The collection persister.</param> /// <param name="batchableCache">The batchable cache.</param> /// <param name="checkCache">Whether to check the cache or just return <see langword="false" /> for all keys.</param> /// <returns>An array of booleans that contains the result for each key.</returns> private bool[] AreCached(List <KeyValuePair <KeyValuePair <CollectionEntry, IPersistentCollection>, int> > collectionKeys, int[] keyIndexes, ICollectionPersister persister, CacheBase batchableCache, bool checkCache) { var result = new bool[keyIndexes.Length]; if (!checkCache || !persister.HasCache || !context.Session.CacheMode.HasFlag(CacheMode.Get)) { return(result); } var cacheKeys = new object[keyIndexes.Length]; var i = 0; foreach (var index in keyIndexes) { var collectionKey = collectionKeys[index].Key; cacheKeys[i++] = context.Session.GenerateCacheKey( collectionKey.Key.LoadedKey, persister.KeyType, persister.Role); } var cacheResult = batchableCache.GetMany(cacheKeys); for (var j = 0; j < result.Length; j++) { result[j] = cacheResult[j] != null; } return(result); }
/// <summary> /// Checks whether the given entity key indexes are cached. /// </summary> /// <param name="entityKeys">The list of pairs of entity keys and their indexes.</param> /// <param name="keyIndexes">The array of indexes of <paramref name="entityKeys"/> that have to be checked.</param> /// <param name="persister">The entity persister.</param> /// <param name="batchableCache">The batchable cache.</param> /// <param name="checkCache">Whether to check the cache or just return <see langword="false" /> for all keys.</param> /// <returns>An array of booleans that contains the result for each key.</returns> private bool[] AreCached(List <KeyValuePair <EntityKey, int> > entityKeys, int[] keyIndexes, IEntityPersister persister, CacheBase batchableCache, bool checkCache) { var result = new bool[keyIndexes.Length]; if (!checkCache || !persister.HasCache || !context.Session.CacheMode.HasFlag(CacheMode.Get)) { return(result); } var cacheKeys = new object[keyIndexes.Length]; var i = 0; foreach (var index in keyIndexes) { var entityKey = entityKeys[index].Key; cacheKeys[i++] = context.Session.GenerateCacheKey( entityKey.Identifier, persister.IdentifierType, entityKey.EntityName); } var cacheResult = batchableCache.GetMany(cacheKeys); for (var j = 0; j < result.Length; j++) { result[j] = cacheResult[j] != null; } return(result); }
/// <summary> /// Checks whether the given collection key indexes are cached. /// </summary> /// <param name="collectionKeys">The list of pairs of collection entries and their indexes.</param> /// <param name="keyIndexes">The array of indexes of <paramref name="collectionKeys"/> that have to be checked.</param> /// <param name="persister">The collection persister.</param> /// <param name="batchableCache">The batchable cache.</param> /// <param name="checkCache">Whether to check the cache or just return <see langword="false" /> for all keys.</param> /// <returns>An array of booleans that contains the result for each key.</returns> private bool[] AreCached(List <KeyValuePair <KeyValuePair <CollectionEntry, IPersistentCollection>, int> > collectionKeys, int[] keyIndexes, ICollectionPersister persister, CacheBase batchableCache, bool checkCache) { var result = new bool[keyIndexes.Length]; if (!checkCache || !persister.HasCache || !context.Session.CacheMode.HasFlag(CacheMode.Get)) { return(result); } // Do not check the cache when disassembling collections from the cached query that were already checked if (QueryCacheQueue != null && collectionKeys.All(o => QueryCacheQueue.WasCollectionEntryChecked(persister, o.Key.Key))) { return(result); } var cacheKeys = new object[keyIndexes.Length]; var i = 0; foreach (var index in keyIndexes) { var collectionKey = collectionKeys[index].Key; cacheKeys[i++] = context.Session.GenerateCacheKey( collectionKey.Key.LoadedKey, persister.KeyType, persister.Role); } var cacheResult = batchableCache.GetMany(cacheKeys); for (var j = 0; j < result.Length; j++) { result[j] = cacheResult[j] != null; } return(result); }
/// <summary> /// Checks whether the given entity key indexes are cached. /// </summary> /// <param name="entityKeys">The list of pairs of entity keys and their indexes.</param> /// <param name="keyIndexes">The array of indexes of <paramref name="entityKeys"/> that have to be checked.</param> /// <param name="persister">The entity persister.</param> /// <param name="batchableCache">The batchable cache.</param> /// <param name="checkCache">Whether to check the cache or just return <see langword="false" /> for all keys.</param> /// <returns>An array of booleans that contains the result for each key.</returns> private bool[] AreCached(List <KeyValuePair <EntityKey, int> > entityKeys, int[] keyIndexes, IEntityPersister persister, CacheBase batchableCache, bool checkCache) { var result = new bool[keyIndexes.Length]; if (!checkCache || !persister.HasCache || !context.Session.CacheMode.HasFlag(CacheMode.Get)) { return(result); } // Do not check the cache when disassembling entities from the cached query that were already checked if (QueryCacheQueue != null && entityKeys.All(o => QueryCacheQueue.WasEntityKeyChecked(persister, o.Key))) { return(result); } var cacheKeys = new object[keyIndexes.Length]; var i = 0; foreach (var index in keyIndexes) { var entityKey = entityKeys[index].Key; cacheKeys[i++] = context.Session.GenerateCacheKey( entityKey.Identifier, persister.IdentifierType, entityKey.EntityName); } var cacheResult = batchableCache.GetMany(cacheKeys); for (var j = 0; j < result.Length; j++) { result[j] = cacheResult[j] != null; } return(result); }