Ejemplo n.º 1
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);
            }
            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);
        }
Ejemplo n.º 2
0
        /// <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>
        /// <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 <EntityKey, int> > entityKeys, int[] keyIndexes, IEntityPersister 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 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 = await(batchableCache.GetManyAsync(cacheKeys, cancellationToken)).ConfigureAwait(false);

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

            return(result);
        }