/// <summary> /// Checks whether the given entity key indexes are cached. /// </summary> /// <param name="entityKeys">The list of pairs of entity keys and thier 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, IBatchableReadOnlyCache 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 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); }
/// <summary> /// Checks whether the given entity key indexes are cached. /// </summary> /// <param name="entityKeys">The list of pairs of entity keys and thier 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, IBatchableReadOnlyCache 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 thier 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, IBatchableReadOnlyCache 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); }
public UpdateTimestampsCache(Settings settings, IDictionary <string, string> props) { string prefix = settings.CacheRegionPrefix; regionName = prefix == null ? regionName : prefix + '.' + regionName; log.Info("starting update timestamps cache at region: {0}", regionName); updateTimestamps = settings.CacheProvider.BuildCache(regionName, props); // ReSharper disable once SuspiciousTypeConversion.Global _batchUpdateTimestamps = updateTimestamps as IBatchableReadOnlyCache; }
public StandardQueryCache(Settings settings, IDictionary <string, string> props, UpdateTimestampsCache updateTimestampsCache, string regionName) { if (regionName == null) { regionName = typeof(StandardQueryCache).FullName; } String prefix = settings.CacheRegionPrefix; if (!string.IsNullOrEmpty(prefix)) { regionName = prefix + '.' + regionName; } Log.Info("starting query cache at region: {0}", regionName); _queryCache = settings.CacheProvider.BuildCache(regionName, props); _batchableReadOnlyCache = _queryCache as IBatchableReadOnlyCache; _batchableCache = _queryCache as IBatchableCache; _updateTimestampsCache = updateTimestampsCache; _regionName = regionName; }