/// <summary>
        /// If a CollectionEntry represents a batch loadable collection, add
        /// it to the queue.
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="ce"></param>
        public void AddBatchLoadableCollection(IPersistentCollection collection, CollectionEntry ce)
        {
            var persister = ce.LoadedPersister;

            if (!batchLoadableCollections.TryGetValue(persister.Role, out var map))
            {
                map = new LinkedHashMap <CollectionEntry, IPersistentCollection>();
                batchLoadableCollections.Add(persister.Role, map);
            }
            map[ce] = collection;

            QueryCacheQueue?.LinkCollectionEntry(ce);
        }
Beispiel #2
0
        /// <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>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
        /// <returns>An array of booleans that contains the result for each key.</returns>
        private async Task <bool[]> AreCachedAsync(List <KeyValuePair <KeyValuePair <CollectionEntry, IPersistentCollection>, int> > collectionKeys,
                                                   int[] keyIndexes, ICollectionPersister persister, CacheBase batchableCache,
                                                   bool checkCache, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            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 = await(batchableCache.GetManyAsync(cacheKeys, cancellationToken)).ConfigureAwait(false);

            for (var j = 0; j < result.Length; j++)
            {
                result[j] = cacheResult[j] != null;
            }

            return(result);
        }